Solved

Script Error on AIX

Posted on 2012-03-27
4
589 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
  • 2
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
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.

733 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