*nix Thread, Script not runnning in crontab? in Technical; I seem to missing athe point somehwre in using crontab?
I have a script which runs fine when I type ...
-
19th June 2009, 12:18 PM #1 Script not runnning in crontab?
I seem to missing athe point somehwre in using crontab?
I have a script which runs fine when I type ./script.sh as I have chmodded the file like this...
chmod ugo+rx moodlebackup.sh
but I can't get it to run in cron.
I have gone in as root, typed crontab -e, and added this line...
52 11 * * Mon-Fri /var/moodlebackup/moodlebackup.sh
But nothing happens at 11:52!
Can anyone make any suggestions. Thanks.
-
-
IDG Tech News
-
19th June 2009, 12:20 PM #2 try
Code:
52 11 * * Mon-Fri /bin/sh /var/moodlebackup/moodlebackup.sh
-
Thanks to CyberNerd from:
-
19th June 2009, 12:37 PM #3 As an aside, you shouldn't place executables in /var (at least not in the FHS) - if it is mounted tmpfs, your script will be nuked when /var gets remounted. All binaries should be in
/bin if they're base system
/sbin if they're base system for the superuser's use
/usr/bin if they're additional
/usr/sbin if they're additional for the superuser's use
Yours should probably go in /usr/bin. If you're going to do that, you should also remove the file extension and ensure you have a shebang at the top of the script (like #!/bin/sh).
-
Thanks to powdarrmonkey from:
-
19th June 2009, 12:55 PM #4 @powdarmonkey.
Am I OK to put the script in a subfolder so it would be /usr/bin/moodlebackups?
Just so i can find it easier later!
I also had #!/bin/bash at the top of my script rather than #!/bin/sh. Not sure if that would make a difference?
Also do i have to take the sh off the end as at the moment that helps my small brain recognise what it is!
Thanks
-
-
19th June 2009, 01:31 PM #5 Strange I don't see my commands in this crontab?
I see this
Code:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
I typed crontab -e while logged on as root so I am guessing that the crontab I edited was for the root user. How could I edit this system crontab.
Also I have my script running now thanks to powdarmonkey's suggestions but now I am adding firther problems by trying to get my moodlecron.php to run.
It is suggested by moodle that I type place
Code:
*/5 * * * * /usr/local/bin/php -q /var/www/moodle/admin/cron.php
in the crontab which I have done and now this isn't running but my backup one is?
Any suggestions?
thanks
-
-
19th June 2009, 01:46 PM #6 I used to edit the crontab like you suggested until I read a shortcut, doh! Not that useful a shortcut.
-
-
19th June 2009, 02:09 PM #7 Ok, there's some confusion here. /etc/crontab is the system crontab, and can run jobs on a user's behalf but can only be changed by root. If user-based schedules are also allowed, crontab -e allows them to be edited by the user (no need to involve root).
If you're going to schedule system-wide jobs, it's good practice to put them in /etc/crontab because you don't need to be root to see them. Saying cat /etc/crontab as a user reveals the jobs, avoiding needing to authenticate and so on. If they are private, putting them in root's user crontab maintains this.
(The user crontabs are actually stored in /var/spool/cron/crontabs, but you must never edit them by hand - always use crontab -e, which does it safely. The system crontab is fair game for the editor of your choice, and cron picks the changes straight up.)
You can store your script in a subdirectory of /usr/bin if you like, but the subdirectory is not searched as part of $PATH. To keep everything sane, put your script and associated resources in a subdirectory of /usr/local if they are architecture-dependent binaries, or /usr/local/share for architecture-independent stuff (/usr and /usr/share on Debian systems) and create symlinks for the executable bits in /usr/bin.
-
-
19th June 2009, 02:27 PM #8
Am I OK to put the script in a subfolder so it would be /usr/bin/moodlebackups?
All locally installed software, that isn't part of the operating system should be in /usr/local or /opt
this stops it from being overwritten with os updates, etc
as posted above, put it in /usr/local then symlink it to /usr/local/bin IMO
-
-
19th June 2009, 02:31 PM #9 
Originally Posted by
CyberNerd
All locally installed software, that isn't part of the operating system should be in /usr/local or /opt
this stops it from being overwritten with os updates, etc
as posted above, put it in /usr/local then symlink it to /usr/local/bin IMO
Ok I have moved the script to /usr/local as suggested.
Can you explain what you mean by symlink it?
Thanks
-
-
19th June 2009, 02:38 PM #10 Code:
sudo ln -s /usr/local/subdirectory/script.sh /usr/local/bin/script.sh
this puts a 'shortcut' (symbolic link) into /usr/local/bin
as /usr/local/bin is in your path, you now don't need type the full path to run it (same as putting script in /usr/bin)
-
-
19th June 2009, 02:42 PM #11 Wow the more I do the less I know!
Would I just run that at the command line, Cybernerd, or would I put that into my crontab?
Just out of interest this is jnow my system crontab that at this moment is not working!
Code:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/bin/moodlebackup
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
33 14 * * Mon-Fri /bin/sh /usr/local/moodlebackup/moodlebackup.sh > /var/log/moodlebackup.log 2>&1
*/5 * * * * curl --silent --compressed http://www.prentonmoodle.co.uk/admin/cron.php > /var/log/moodlecron.log 2>&1
-
-
19th June 2009, 02:49 PM #12 I think you need to specify the user
-
-
19th June 2009, 02:50 PM #13 You've missed the user specification out of your two additional lines. This is one of the major differences between the system table and the user tables. (Read the file header comment carefully.)
-
-
19th June 2009, 02:55 PM #14 I'm not just saying this but I spotted that as soon as I posted it, honest!
I have added root to the user, so I'll give it another whirl.
thanks
-
-
19th June 2009, 03:23 PM #15 All seems to be going ok now.
Thanks to everybody who helped me out.
-
SHARE:
Similar Threads
-
By Hightower in forum *nix
Replies: 4
Last Post: 17th March 2009, 11:24 AM
-
By Paul_L in forum Scripts
Replies: 6
Last Post: 2nd October 2008, 02:33 PM
-
By dhicks in forum Coding
Replies: 0
Last Post: 30th September 2008, 03:24 PM
-
By Galway in forum Windows
Replies: 3
Last Post: 29th August 2007, 11:00 AM
-
By wesleyw in forum Scripts
Replies: 4
Last Post: 5th July 2007, 01:58 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules