Solved

simple scripting question

Posted on 2010-11-08
9
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Progress
Introduction to Processes
Suggested Courses

623 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