Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > cron script problem

cron script problem
Thread Tools
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Sep 8, 2004, 09:38 AM
 
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
Reply With Quote
Sep 8, 2004, 11:14 AM
 
'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
Reply With Quote
Sep 8, 2004, 12:22 PM
 
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
Reply With Quote
Sep 8, 2004, 01:20 PM
 
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
Reply With Quote
Sep 9, 2004, 03:26 PM
 
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"

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:47 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2