sportingchiefs
Posts: 9
Joined: Thu May 01, 2014 3:16 am

[SOLVED] Help with Crontab

Wed Oct 15, 2014 3:16 pm

Good morning all,

I seem to be having some issues with crontab lately and since I don't know much (or really anything) about it I was hoping you all could give me some pointers and help me get this pi running correctly!
OS: Raspbian (9 September release)
(pup.sh is my shell script that I have saved as root to run my raspivid command and is saved in /home/pi/pup.sh)
I created the pup.sh and the crontab as root (sudo bash right? still new to all of this)

I have set up the raspberry pi camera and am running it with raspivid off a tutorial that I followed (can't link it here since I can't access the site at work). The raspivid is working great and is streaming the video to my ustream account just like it is supposed to. I have set up the raspivid as a way to monitor our new puppy while at work. I don't want to leave the camera running all the time so I was trying to get it working with crontab so that it will start and stop when I want it to. I tried using killall in a previous attempt with crontab to stop the raspivid at the appropriate time and was having issues when doing that. This time I've decided to just reboot when I want the raspivid to stop. Here's the code that I'm using in root crontab:

Code: Select all

00 0 * * * /sbin/shutdown -r now
00 7 * * 1-5 screen -d -m /home/pi/pup.sh
00 11 * * 1-5 /sbin/shutdown -r now
00 12 * * 1-5 screen -d -m /home/pi/pup.sh
00 17 * * 1-5 /sbin/shutdown -r now
Now I ran the "screen -d -m /home/pi/pup.sh" command by itself and it worked. However, this morning, I waited on my laptop at 0700 and nothing ran. Checked "top" and raspivid wasn't in the list of processes. I did try a different "screen" command

Code: Select all

/usr/bin/screen -dmS /home/pi/pup.sh
and changed the time and that didn't work either. Any ideas on what I'm doing wrong? I appreciate any help or advice in advance!

- Tyler
Last edited by sportingchiefs on Sat Oct 25, 2014 2:19 pm, edited 1 time in total.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Help with Crontab

Wed Oct 15, 2014 3:24 pm

Code: Select all

00 0,11,17 * * * /sbin/shutdown -r now
00 7,12 * * 1-5 /usr/bin/screen -d -m /home/pi/pup.sh
looking at the error messages for cron may help

but you could change the time limits on capture
raspivid -t xxx #timeout in ms

run it for an hour or 2 or 4 or whatever
also
check the script to see what is being done there

which crontab is being used for the above ?
sudo crontab -e
or crontab -e
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

sportingchiefs
Posts: 9
Joined: Thu May 01, 2014 3:16 am

Re: Help with Crontab

Wed Oct 15, 2014 3:27 pm

run it for an hour or 2 or 4 or whatever
also
check the script to see what is being done there

which crontab is being used for the above ?
sudo crontab -e
or crontab -e
When I log in I do "sudo bash" first and then "crontab -e"

I've thought about doing the time thing with the milliseconds but for that to work I would have to get crontab to run the .sh first.
looking at the error messages for cron may help
how would I do that?

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Help with Crontab

Wed Oct 15, 2014 3:33 pm

the shutdown will not run as user [
cat /var/log/syslog
may help to find cron errors
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

sportingchiefs
Posts: 9
Joined: Thu May 01, 2014 3:16 am

Re: Help with Crontab

Wed Oct 15, 2014 3:39 pm

RaTTuS wrote:cat /var/log/syslog
may help to find cron errors
I head home for lunch in about 20 min so I will check for errors then.
the shutdown will not run as user
I'm not sure what you mean by this, can you clarify more? From my understanding I'm running everything as root. Thanks for your help so far, I do appreciate it.

sportingchiefs
Posts: 9
Joined: Thu May 01, 2014 3:16 am

Re: Help with Crontab

Wed Oct 15, 2014 4:35 pm

So I updated the crontab to mirror:

Code: Select all

00 0,11,17 * * * /sbin/shutdown -r now
00 7,12 * * 1-5 /usr/bin/screen -d -m /home/pi/pup.sh
(I changed the 00 to different minutes like 29, 31 to get it to start while I'm home)
I watched "top" and sure enough at the specified minute raspivid would show up in the list of processes and then shortly disappeared from the list. Could the time in crontab and the time specified in the .sh (raspivid -t XXX) be throwing each other off? Here is what I found in "cat /var/log/syslog"

Code: Select all

Oct 15 11:25:01 raspberrypi /USR/SBIN/CRON[2236]: (root) CMD (/usr/bin/screen -d -m /home/pi/pup.sh)
Oct 15 11:25:40 raspberrypi crontab[2252]: (root) BEGIN EDIT (root)
Oct 15 11:26:01 raspberrypi crontab[2252]: (root) REPLACE (root)
Oct 15 11:26:01 raspberrypi crontab[2252]: (root) END EDIT (root)
Oct 15 11:26:01 raspberrypi /usr/sbin/cron[2079]: (root) RELOAD (crontabs/root)
Oct 15 11:27:01 raspberrypi /USR/SBIN/CRON[2258]: (root) CMD (/usr/bin/screen -d -m /home/pi/pup.sh)
Oct 15 11:28:27 raspberrypi crontab[2271]: (root) BEGIN EDIT (root)
Oct 15 11:28:39 raspberrypi crontab[2271]: (root) REPLACE (root)
Oct 15 11:28:39 raspberrypi crontab[2271]: (root) END EDIT (root)
Oct 15 11:29:01 raspberrypi /usr/sbin/cron[2079]: (root) RELOAD (crontabs/root)
Oct 15 11:29:01 raspberrypi /USR/SBIN/CRON[2277]: (root) CMD (/usr/bin/screen -d -m /home/pi/pup.sh)

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Help with Crontab

Thu Oct 16, 2014 8:27 am

post the script that you are using pup.sh
you probably don't need to run this under screen as your running it from cron
try without
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

sportingchiefs
Posts: 9
Joined: Thu May 01, 2014 3:16 am

Re: Help with Crontab

Sat Oct 25, 2014 2:19 pm

I have fixed this. You were right I didn't need to run screen since it was in cron but this is how I solved the issue (whether necessary or not it works! :D )

I created another shell script called "runpup.sh" that looks like this:

Code: Select all

#!/bin/sh
echo "This script is about to start the puppy cam."
/usr/bin/sudo /home/pi/pup.sh
echo "This script has started the puppy cam!"
Now I had created runpup.sh initially without "/usr/bin/sudo" and it wasn't running. As soon as I added "/usr/bin/sudo" to it, it has been working flawlessly. Thank you for your help and hopefully this will help anybody else who has this issue!

Return to “Troubleshooting”