Jump to content


Photo

Shell script is not running properly / cronjob


  • Please log in to reply
4 replies to this topic

#1 squidden

  • Member
  • 9 posts

+1
Neutral

Posted 25 May 2012 - 14:06

Hi,

I have a problem with one of my scripts. It works perfectly when I run it manually but as soon as I add it to crontab it starts a new process.
After 10 min I have 10 different processes running.

Maybe someone can point me in the right direction (I'm on OpenPLi-2.1-beta-dm800se)?

#!/bin/sh
if ps |grep -v grep |grep -c 1111:localhost ;
then
echo "SSH Tunnel... ok"
else
echo "SSH Tunnel... restarting"
/usr/bin/ssh -y -i /etc/dropbear/dropbear_rsa_host_key -f -R 1111:localhost:23 -N -R 2222:localhost:80 -N user@192.168.0.2 -p 22
fi

Crontab looks like this:

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
*/1 * * * * /usr/sbin/check.sh

Thanks in advance!

Re: Shell script is not running properly / cronjob #2 Pedro_Newbie

  • Senior Member
  • 4,631 posts

+225
Excellent

Posted 25 May 2012 - 15:51

What happens if you only use */1 * * * * /usr/sbin/check.sh in the crontab

Edited by Pedro_Newbie, 25 May 2012 - 15:51.


Re: Shell script is not running properly / cronjob #3 hemispherical1

  • Senior Member
  • 1,596 posts

+49
Good

Posted 25 May 2012 - 16:10

*/1 * * * * = * * * * *, sounds like it's working as expected... ;)

--
hemi

Ps. You might want an exit before the else.

Edited by hemispherical1, 25 May 2012 - 16:16.


Re: Shell script is not running properly / cronjob #4 squidden

  • Member
  • 9 posts

+1
Neutral

Posted 25 May 2012 - 20:08

*/1 * * * * = * * * * *, sounds like it's working as expected... ;)

--
hemi

Ps. You might want an exit before the else.


Ahh... so the script should look like this?

#!/bin/sh
if ps |grep -v grep |grep -c 1111:localhost ;
then
echo "SSH Tunnel... ok"
exit
else
echo "SSH Tunnel... restarting"
/usr/bin/ssh -y -i /etc/dropbear/dropbear_rsa_host_key -f -R 1111:localhost:23 -N -R 2222:localhost:80 -N user@192.168.0.2 -p 22
fi

//Squidden

Re: Shell script is not running properly / cronjob #5 hemispherical1

  • Senior Member
  • 1,596 posts

+49
Good

Posted 25 May 2012 - 22:03

I would think so. See if it works better...

--
hemi


2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users