Solved

Running a command remotely using ksh

Posted on 2014-10-23
2
164 Views
Last Modified: 2014-10-29
I want to loop through all of our Solaris servers using ssh and make sure the patch for shellshock has been applied.  The check for it is this:
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

if it prints "vulnerable", you need to have the patch applied.  The problem is that the special characters in that command break when I run through a list of our servers in a for loop trying to ssh to them.  I've tried \ them out, but to no avail.

The loop looks like this:
for i in $serverlist)
do
      ssh $i env x='() { :;}; echo vulnerable' bash -c "echo this is a test" |grep vulnerable
      if [ $? -eq 0 ]
      then
              print $i needs patch
      fi
done



Any help would be appreciated.

David
0
Comment
Question by:David Aldridge
2 Comments
 
LVL 20

Accepted Solution

by:
tfewster earned 500 total points
Comment Utility
# ssh $i 'env x=\'() { :;}; echo vulnerable\' bash -c "echo this is a test" |grep vulnerable'
Or
# ssh $i "env x='() { :;}; echo vulnerable' bash -c 'echo this is a test' |grep vulnerable"
Or
# cat test.sh
env x='() { :;}; echo vulnerable' bash -c "echo this is a test" |grep vulnerable
      if [ $? -eq 0 ]
      then
              print "`hostname` needs patch"
      fi

# for i in $serverlist)
do
      scp test.sh $i:/tmp
      ssh $i /tmp/test.sh
done
0
 
LVL 1

Author Closing Comment

by:David Aldridge
Comment Utility
Thanks! Sorry it took me so long to get back.  I didn't get an email saying an answer had been posted.  Great solution though.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now