Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

simple scripting question

Posted on 2010-11-08
9
Medium Priority
?
385 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Progress
Suggested Courses

730 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