Solved

simple scripting question

Posted on 2010-11-08
9
376 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
Comment Utility
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
Comment Utility
... 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
Comment Utility
Thanks  a lot for all of your helps. It works fine now. Thanks again.
0
 

Author Closing Comment

by:mokkan
Comment Utility
Thank you all.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
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.

744 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

13 Experts available now in Live!

Get 1:1 Help Now