Solved

Script Error on AIX

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

914 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

17 Experts available now in Live!

Get 1:1 Help Now