Solved

simple scripting question

Posted on 2010-11-08
9
381 Views
Last Modified: 2012-05-10
I'm trying to check tivoli process and getting wrong result, what I'm doing wrong here?


`ssh $USR@$hosts ps afxS | grep -i tivoli`
if [ "$?" -eq "0" ]; then
      echo "TIVOLI is intalled and running" >> $LOG
else
       echo "it is not running "  >> $LOG

0
Comment
Question by:mokkan
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 6

Assisted Solution

by:brb6708
brb6708 earned 83 total points
ID: 34084042
if you simply pipe "grep -i tivoli" you get the grep command as well (grep -i tivoli contains 'tivoli')

so  

`ssh $USR@$hosts ps afxS | grep -v 'grep' | grep -i tivoli`

should do the job
0
 
LVL 13

Accepted Solution

by:
dhoffman_98 earned 167 total points
ID: 34084104
1. You haven't initiated your $LOG variable
2. You have no end if statement.
3. Your $? result is going to be the result of the SSH command, not the PS command on the remote system. $? will check to see the result of the preceeding command. From your remote system, the preceeding command was "ssh".

Perhaps you could run something different:

LOG = /path/to/logfile
TCount = `ssh $USR@$hosts ps afxS | grep -i tivoli` | wc -l
if [ "$TCount" -ge "0" ]; then
      echo "TIVOLI is intalled and running" >> $LOG
else
       echo "it is not running "  >> $LOG
end if

Open in new window

0
 
LVL 13

Assisted Solution

by:dhoffman_98
dhoffman_98 earned 167 total points
ID: 34084112
Yep... forgot to discount the grep line as brb6708 stated. So use his -v to ignore the grep line as well and combine that with my suggestion.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 34084160
if ssh "$USR@$hosts ps afxS | grep -v 'grep' | grep -q -i 'tivoli`" &&  echo "TIVOLI is installed and running" >> $LOG || echo "it is not running"  >> $LOG


 
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 34084169
Sorry, quote at the wrong place!
if ssh $USR@$hosts "ps afxS | grep -v 'grep' | grep -q -i 'tivoli`" &&  echo "TIVOLI is installed and running" >> $LOG || echo "it is not running"  >> $LOG

 
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 34084191
... and forget the "if"! Must have been confused by the other posts!
ssh $USR@$hosts "ps afxS | grep -v 'grep' | grep -q -i 'tivoli`" &&  echo "TIVOLI is installed and running" >> $LOG || echo "it is not running"  >> $LOG

 
 
 
0
 

Author Comment

by:mokkan
ID: 34084407
Thanks  a lot for all of your helps. It works fine now. Thanks again.
0
 

Author Closing Comment

by:mokkan
ID: 34180553
Thank you all.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

860 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