Computing.Net > Forums > Programming > Bash Script : missing

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Bash Script : missing

Reply to Message Icon

Name: Satanic_Vegeta
Date: March 13, 2009 at 16:35:28 Pacific
OS: Debian Lenny
Subcategory: Batch
Comment:

Hi there, I have a noob question, I dont find the bug:

[CODE]
1: #!/bin/sh
2: if [ pgrep ktorrent &> /dev/null ] ; then
3: echo "ktorrent not running... Restarting...";
4: ktorrent;
5: exit 0;
6: else
7: pgrep ktorrent;
8: echo "ktorrent allready running!";
9: exit 0;
10: fi
if [ pgrep pidgin &> /dev/null ] ; then
echo "Pidgin not running... Restarting...";
pidgin;
exit 0;
15: else
pgrep pidgin;
echo "Pidgin allready running!";
exit 0;
19: fi
[/CODE]

Brings me:

[QUOTE]
:~/$ sh torrentcron.sh
torrentcron.sh: 10: ]: not found
[: 10: missing ]
7309
ktorrent allready running!
[/QUOTE]

I need this for a cronjob...

Thx



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 14, 2009 at 12:30:09 Pacific
Reply:

Why not try checking the exit code, $?, of the command.
if ktorrent is running the value is 0. If not, the value is probably 1.


#!/bin/sh

pgrep ktorrent &> /dev/null
if  [ $? -eq 0 ]
then
   echo "ktorrent allready running!"
else
   echo "ktorrent not running... Restarting..."
fi


0

Response Number 2
Name: Satanic_Vegeta
Date: March 21, 2009 at 02:54:34 Pacific
Reply:

Thank you so much, it works :D


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Bash Script : missing

Bash script help www.computing.net/answers/programming/bash-script-help/10720.html

Need Help with Bash script www.computing.net/answers/programming/need-help-with-bash-script/16687.html

Bash script to start application www.computing.net/answers/programming/bash-script-to-start-application/18255.html