RockDawg Posted January 27, 2010 Share Posted January 27, 2010 I have a script that runs fin when I manually type it in, but it doesn't seem to run via cron. I've never set up a cron job before, but from what I've read I think I have it right. Can anyone tell me why it won't run? I ran crontab -e and entered this: 53 * * * * /boot/packages/xbmcsync/python xbmcsync.py >/dev/null I'm expecting that to run every hour at 53 past the hour, but it never seems to run. Link to comment
Joe L. Posted January 27, 2010 Share Posted January 27, 2010 I have a script that runs fin when I manually type it in, but it doesn't seem to run via cron. I've never set up a cron job before, but from what I've read I think I have it right. Can anyone tell me why it won't run? I ran crontab -e and entered this: 53 * * * * /boot/packages/xbmcsync/python xbmcsync.py >/dev/null I'm expecting that to run every hour at 53 past the hour, but it never seems to run. Instead of sending the output to /dev/null, send it to a file so you can see any errors, like this: 53 * * * * /boot/packages/xbmcsync/python xbmcsync.py >>/tmp/xmbc_log 2>&1 Link to comment
RockDawg Posted January 27, 2010 Author Share Posted January 27, 2010 Thanks, that at least shows me it ran but errored. It returned: /bin/sh: /boot/packages/xbmcsync/python: No such file or directory How do I handle that? I need to type python before the script file name when I type it manually. Link to comment
Joe L. Posted January 27, 2010 Share Posted January 27, 2010 Thanks, that at least shows me it ran but errored. It returned: /bin/sh: /boot/packages/xbmcsync/python: No such file or directory How do I handle that? I need to type python before the script file name when I type it manually. It indicates that python is not installed in the xbmcsync directory Type which python to learn its correct path Link to comment
RockDawg Posted January 28, 2010 Author Share Posted January 28, 2010 EDIT: I was over complicating things. The line I needed was 0 * * * * python /boot/packages/xbmcsync/xbmcsync.py. Thanks for your help Joe L. Link to comment
RockDawg Posted January 29, 2010 Author Share Posted January 29, 2010 Hopefully this will be my last question concerning this. I have the cron job working properly, but obviously it's lost on a reboot. I searched around and found a script someone posted that adds lines to crontab. I figured I could edit it and get it to work but I'm having a problem. When I run the script it puts my lines in crontab, but all other contents of crontab are then removed. What do I have wrong? Here is my script: #!/bin/bash # Extract root's crontable. crontab -u root -l # Append new entries to root's crontable cat <<-EOF >> /tmp/crontab.tmp # Run xbmcsync.py hourly 8 * * * * python /boot/scripts/xbmcsync/xbmcsync.py EOF # Update root's crontable. crontab /tmp/crontab.tmp -u root rm /tmp/crontab.tmp Here is the resulting crontab: root@Tower1:~# crontab -e # Run xbmcsync.py hourly 8 * * * * python /boot/scripts/xbmcsync/xbmcsync.py[/code} Link to comment
Joe L. Posted January 29, 2010 Share Posted January 29, 2010 Hopefully this will be my last question concerning this. I have the cron job working properly, but obviously it's lost on a reboot. I searched around and found a script someone posted that adds lines to crontab. I figured I could edit it and get it to work but I'm having a problem. When I run the script it puts my lines in crontab, but all other contents of crontab are then removed. What do I have wrong? Here is my script: #!/bin/bash # Extract root's crontable. crontab -u root -l # Append new entries to root's crontable cat <<-EOF >> /tmp/crontab.tmp # Run xbmcsync.py hourly 8 * * * * python /boot/scripts/xbmcsync/xbmcsync.py EOF # Update root's crontable. crontab /tmp/crontab.tmp -u root rm /tmp/crontab.tmp Here is the resulting crontab: root@Tower1:~# crontab -e # Run xbmcsync.py hourly 8 * * * * python /boot/scripts/xbmcsync/xbmcsync.py[/code} Your script is missing a few parts. 1. The initial "crontab -l" did not redirect the output to crontab.tmp. The intent is to append to its current contents the new crontab command. I highlighted it in "blue" below. 2. You did not check to see if the line was already in the crontab before adding it again. Those lines are in green 3. You did not copy the new crontab to "/var/spool/cron/crontabs/root-" Failing to do this will result in your new entry being deleted by unRAID if you make any changes via the unRAID interface to the settings for the "mover" #!/bin/bash # Extract root's crontable. crontab -u root -l >/tmp/crontab.tmp grep -q "xbmcsync.py" /tmp/crontab.tmp 1>/dev/null 2>&1 if [ "$?" = "1" ] then # Append new entries to root's crontable cat <<-EOF >> /tmp/crontab.tmp # Run xbmcsync.py hourly ( Every hour at 8 minutes past the hour ) 8 * * * * python /boot/scripts/xbmcsync/xbmcsync.py EOF # Update root's crontable. crontab /tmp/crontab.tmp -u root # If we don't copy the new crontab to "root-", the additions will be deleted # if you use the management interface to make any changes. cp /tmp/crontab.tmp /var/spool/cron/crontabs/root- fi rm /tmp/crontab.tmp Link to comment
RockDawg Posted January 30, 2010 Author Share Posted January 30, 2010 I guess I didn't understand it as much as I thought I did. Some of that was in the original script before I modified it, but I removed thinking it wasn't needed. I failed to grasp that the script copied the crontab to a temp file, appended the temp file and then copied the temp file as the new crontab. I was thinking it was changing the original crontab file. Anyhow, your script worked great. Again, thanks so much for all your help! Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.