Bash Script : missing

March 13, 2009 at 16:35:28
Specs: Debian Lenny
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


See More: Bash Script : missing

Report •


#1
March 14, 2009 at 12:30:09
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


Report •

#2
March 21, 2009 at 02:54:34
Thank you so much, it works :D

Report •

Related Solutions


Ask Question