Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

simple scripting question

Posted on 2010-11-08
9
Medium Priority
?
386 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 332 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 668 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 668 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 1000 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 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

916 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