Dayned89
Posts: 10
Joined: Thu Jan 14, 2016 10:05 pm

crontab

Sun Jan 17, 2016 8:45 pm

Not sure if this is the right forum or if this is the right place to ask, but google has failed to help me so far.

I'm using my pi as a headless torrentbox however deluge-web crashes all the time. I decided to try making a script to check if it works and to start it if it doesn't. I knew nothing about bash before starting this project so it required a lot of googles help but now if I run "sh ~/scripts/restart-deluge-web.sh" it will restart it and output the result (either that it was working already, or that it restarted it ok or that it failed to restart it).

Next to get it to run every min so that I don't have to check it all the time. This is where I am hitting a brick wall.

crontab - l outputs: * * * * * /home/pi/scripts/restart-deluge-web.sh

My logs however say that the program is not being run but is instead only running when I manually run it. As I can run it I know it is executable and that it works ok when I do it. I added that to crontab using my account and using "crontab - e" and I've tried restarting crontab with "sudo /etc/init.d/cron restart" but still nothing.

Any ideas on what I could try next?

Dayned89
Posts: 10
Joined: Thu Jan 14, 2016 10:05 pm

Re: crontab

Sun Jan 17, 2016 9:03 pm

Having looked at it further I've found that the cron service crond isn't running. If I try to start it it tells me that I don't have permission. Does this mean all crontabs have to be run by root? How do I change this? ie is there a cron group and how do I join it if so.

User avatar
rpdom
Posts: 20042
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: crontab

Sun Jan 17, 2016 9:05 pm

1. Is your script marked as executable? If you do "ls -l /home/pi/scripts/restart-deluge-web.sh", do you get

Code: Select all

-rw-r--r-- 1 pi pi 1614 Jan 17 20:59 /home/pi/scripts/restart-deluge-web.sh
(ignore the date/time/size, mine is a dummy file)
If so, you need to make it executable with "chmod +x /home/pi/scripts/restart-deluge-web.sh" and it should now look like

Code: Select all

-rwxr-xr-x 1 pi pi 1614 Jan 17 20:59 /home/pi/scripts/restart-deluge-web.sh
2. Have you got a "shebang" (#!......) line at the start of your script to tell it what program to use to run it? The first line should be something like "#!/bin/bash" or "#!/bin/sh" for a shell script.

3. Start cron with "sudo service cron start". The cron daemon (controlling program) runs as root, but the individual crontab entries are run as their respective userids.

Dayned89
Posts: 10
Joined: Thu Jan 14, 2016 10:05 pm

Re: crontab

Sun Jan 17, 2016 9:16 pm

Now I'm even more confused :S

$ service crond start
Failed to start crond.service: Access denied
$ sudo service crond start
Failed to start crond.service: Unit crond.service failed to load: No such file or directory.

User avatar
rpdom
Posts: 20042
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: crontab

Sun Jan 17, 2016 9:20 pm

Dayned89 wrote:Now I'm even more confused :S

$ service crond start
That's not what I said.
rpdom wrote:sudo service cron start
Note the "sudo" at the start to give you root permissions, and the service is just called "cron", not "crond".

Dayned89
Posts: 10
Joined: Thu Jan 14, 2016 10:05 pm

Re: crontab

Sun Jan 17, 2016 9:24 pm

rpdom wrote:1. Is your script marked as executable? If you do "ls -l /home/pi/scripts/restart-deluge-web.sh", do you get

Code: Select all

-rw-r--r-- 1 pi pi 1614 Jan 17 20:59 /home/pi/scripts/restart-deluge-web.sh
(ignore the date/time/size, mine is a dummy file)
If so, you need to make it executable with "chmod +x /home/pi/scripts/restart-deluge-web.sh" and it should now look like

Code: Select all

-rwxr-xr-x 1 pi pi 1614 Jan 17 20:59 /home/pi/scripts/restart-deluge-web.sh
2. Have you got a "shebang" (#!......) line at the start of your script to tell it what program to use to run it? The first line should be something like "#!/bin/bash" or "#!/bin/sh" for a shell script.

3. Start cron with "sudo service cron start". The cron daemon (controlling program) runs as root, but the individual crontab entries are run as their respective userids.
1. What is the difference between chmod -x and chmod +x? I have done the -x one and it was then allowing me to run it, what is the difference with the +x?

3. Didn't seem to work (see error above) however the script is working now according to the logs so thanks for the help :)


Your reply:

I ran that command before reading your reply, I read on another forum that the daemon was started with crond.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: crontab

Sun Jan 17, 2016 9:39 pm

Dayned89 wrote: I'm using my pi as a headless torrentbox however deluge-web crashes all the time.

Any ideas on what I could try next?
Rather than fudge it with a restart every minute, why does it fail in the first place? Fix that, and the rest is moot.

User avatar
rpdom
Posts: 20042
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: crontab

Sun Jan 17, 2016 9:40 pm

Dayned89 wrote:1. What is the difference between chmod -x and chmod +x?
With chmod, the + adds the permissions and the - removes them.

+x will add the "eXecute" permissions, and -x will remove them. You can type "man chmod" (or look here http://manpages.debian.org/cgi-bin/man.cgi?query=chmod) to read the manual for the chmod command which explains all that.

Glad to hear you got your script running :)

Return to “Beginners”