nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Can someone please explain this to me

This is a discussion on Can someone please explain this to me within the Shell scripting forums, part of the Development/Scripting category; if [ `/opt/bin/ps ax | grep -c transmission` -gt 1 ] then echo "<td>Running</td>" else echo "<td>NOT running</td>" fi This ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 12-25-2007, 07:02 PM
Junior Member
User
 
Join Date: Dec 2007
My distro: Ubuntu
Posts: 2
Rep Power: 0
gyterpena is on a distinguished road
Default Can someone please explain this to me

if [ `/opt/bin/ps ax | grep -c transmission` -gt 1 ]
then
echo "<td>Running</td>"
else
echo "<td>NOT running</td>"
fi


This is part of script that generate web site with some router statistics.
What I don't understand is the "-gt 1" part. What I think it does is decrease output of grep -c by one. But in different script I have "if [ $count -eq 0 ]"
whole script is here . If someone can point me to man page where I can find more info about it.
thanks
Peter
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-28-2007, 06:44 PM
Administrator
User
 
Join Date: Apr 2007
Posts: 10
Rep Power: 10
root has disabled reputation
Default

If output if greater than 1 process is running else it is not running
Reply With Quote
  #3 (permalink)  
Old 12-29-2007, 01:25 AM
Junior Member
User
 
Join Date: Dec 2007
My distro: SuSE 9.3 Pro
Posts: 1
Rep Power: 0
keelerm is on a distinguished road
Default

The -c switch for grep returns a count of lines that match the given pattern.

By saying
Code:
if [ `/opt/bin/ps ax | grep -c transmission` -gt 1 ]
you're checking that there are at least two processes running with the pattern "transmission" in the output.

The -gt just means greater than. There are others of a similar form :
lt -- less than
eq -- equal to
ne -- not equal to

And so on and so forth.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 03:05 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36