?
Solved

Running a command remotely using ksh

Posted on 2014-10-23
2
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
tfewster earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 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