Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Script Error on AIX

Posted on 2012-03-27
4
Medium Priority
?
593 Views
Last Modified: 2012-08-14
When I run the below command, The output is below

$ sudo /admin/bin/rsh aixdev21 lslpp -l |grep splunk
  aixdev21:
  splunk.db2.rte          2.2.3.2  COMMITTED  SPLUNK v2 Client

So Splunk is a customized tool in our environment, I am planning to get an output of splunk versions across the environment and I am expecting the output to be

- HOSTNAME    SPLUNK-VERSION    OSLEVEL

So I went ahead and wrote a script

####################################################
for i in `cat $SERVER_LIST`
do
ping -c 2 -w 1 $i >> /dev/null
       if [ $? -eq 1 ]; then
        echo "$i did not respond"
       else
        SPLUNK = `sudo /admin/bin/rsh $i "lslpp -l|grep splunk" | grep Client | grep -v $i | awk '{print $2}'`
        OSLEVEL = `sudo /admin/bin/rsh $i  "OSLEVEL = `oslevel -s`"`
        echo "$i   $SPLUNK    $OSLEVEL"
         fi
exit 0

############################################################

But I am getting an error running, The error is ksh cannot identify SPLUNK and OSLEVEL...
So can someone help me with the script...

Thanks
Steve
0
Comment
Question by:mnis2008
[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
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 37772597
Please don't use spaces around the equal signs "=" when assigning variables:

SPLUNK=`sudo /admin/bin/rsh $i "lslpp -l|grep splunk" | grep Client | grep -v $i | awk '{print $2}'`

The second command will not work. Try this:

OSLEVEL=`sudo /admin/bin/rsh $i  oslevel -s`

I, personally, do prefer the $( ) notation:

SPLUNK=$(sudo /admin/bin/rsh $i "lslpp -l|grep splunk" | grep Client | grep -v $i | awk '{print $2}')

OSLEVEL=$(sudo /admin/bin/rsh $i  oslevel -s)
0
 

Author Comment

by:mnis2008
ID: 37772760
I am able to run the SPLUNK and OSLEVEL commands but when I do a "echo $SPLUNK" or echo $OSLEVEL" I am not able to get the output
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37772847
The commands as posted in my last comment should work just fine.

What is the output if you don't capture it in a variable?


i=myhost
sudo /admin/bin/rsh $i "lslpp -l|grep splunk" | grep Client | grep -v $i | awk '{print $2}'

and

i=myhost
sudo /admin/bin/rsh $i  oslevel -s

Is your rsh indeed in /admin/bin ? Is this a special setup for sudo?
0
 

Author Comment

by:mnis2008
ID: 37773477
Sorry it worked...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Fine Tune your automatic Updates for Ubuntu / Debian
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

618 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