Solved

Running a command remotely using ksh

Posted on 2014-10-23
2
182 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 21

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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