 |
 |
cron script problem
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
I wrote a script to back up one of my Mac OS X server's LDAP directory, schema, and password server database then threw it in a cron job to run at 12:01 every morning. When I test the script in a root shell it runs fine (checks if backup directory exists, creates directory, runs slapcat, mkpassdb, etc), yet when it runs via its cron job all it does is create the directory for that day's backup and puts nothing inside of it.
I'm wondering if there is any common problems with this setup that I should check for? Thanks.
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2002
Location: Red Bluff, CA
Status:
Offline
|
|
'sup buddy?
i haven't used cron too much, but i'm wondering if you have to launch cron with root privs, aka via sudo.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
I suspect that the problem is paths to executables. Remember that the cron shell for the root user has almost no environment. You generally either set the path explicitly in your script, or you use full paths to executables.
You can send the output of the cron job to a file and look at it to check for errors. Assuming you are using /bin/sh for your script shell, you can replace it with /bin/sh -x and get debugging information as each command is executed.
Also, check the return status ($?) for each command. Normally UNIX commands return an exit status of 0 on success. Something like this
Code:
some_command
if [ $? -ne 0 ]; then
echo "Sorry, an error occurred".
fi
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Originally posted by darkcore:
'sup buddy?
i haven't used cron too much, but i'm wondering if you have to launch cron with root privs, aka via sudo.
Get back to work, buddy! Hah. Yeah, I've put the command in root's crontab.
Originally posted by Arkham_c:
I suspect that the problem is paths to executables. Remember that the cron shell for the root user has almost no environment. You generally either set the path explicitly in your script, or you use full paths to executables.
Ah, I was making sure to use absolute paths for file and folder names but I had not been using absolute paths for the commands I was running. I prepended "/usr/sbin" to the few commands that I was running (slapcat, mkpassdb) so hopefully that will be the final fix. We'll see tonight at 12:01.
Thanks for the tip 
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
I just checked my server and the backups ran fine this morning. Hooray. Absolute paths for any binary NOT in /bin are a must.
Thanks for the tips, fellas 
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|