Solved

Script Error on AIX

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now