Running a command remotely using ksh

Posted on 2014-10-23
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)
      ssh $i env x='() { :;}; echo vulnerable' bash -c "echo this is a test" |grep vulnerable
      if [ $? -eq 0 ]
              print $i needs patch

Any help would be appreciated.

Question by:David Aldridge
LVL 20

Accepted Solution

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

# for i in $serverlist)
      scp $i:/tmp
      ssh $i /tmp/

Author Closing Comment

by:David Aldridge
ID: 40411341
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.

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Doing a DR (Disaster Recovery) Test on Red Hat Linux Servers. 2 114
Unix Question 19 50
AWS CLI - Instances, Volumes & Tagging 2 94
Control Number of Log Files -Perl 7 72
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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.

770 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