Solved

Script Error on AIX

Posted on 2012-03-27
4
587 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

773 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