Solved

Running a command remotely using ksh

Posted on 2014-10-23
2
168 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
ID: 40400546
# 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
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

863 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

19 Experts available now in Live!

Get 1:1 Help Now