Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a problem with cron tasks. Previously this script worked fine on Mac OS X 10.6 server, but when I initialize it on Lion (client), this script stopped working.

Basically, this .bat file calls a jar file (that invokes a loop of mysqldump commands) to backup several databases on several servers, and runs perfectly if launched by the shell.

cd /Users/nameoftheuser/Desktop/backupper 
/usr/bin/java -cp .:Backupper.jar:lib/mail.jar backupper.Main "/Users/nameoftheuser/Desktop/backupper/listasiti.txt" "/Users/nameofthe/Desktop/backupper/config.properties

But if the cron launches the same .bat file, the generated database backups are 0 bytes.

The cron entry is:

0     0     sh /Users/path/to/file.bat

I believe that the problem is that cron doesn't run as root. Or what else?

share|improve this question
    
So what's in your script, please? We can't magically guess what works and what doesn't. If you want to run it from root's crontab, just see: superuser.com/questions/344398/… — also: How do you edit the crontab initially? Do you call the script from the shell using sh … too? –  slhck Nov 5 '11 at 15:21
    
The bat entry is: cd /Users/nameoftheuser/Desktop/backupper /usr/bin/java -cp .:Backupper.jar:lib/mail.jar backupper.Main "/Users/nameoftheuser/Desktop/backupper/listasiti.txt" "/Users/nameofthe/Desktop/backupper/config.properties" - I edited the crontab with nano, logged in terminal with the same user of where the script is stored, using tabs instead of spaces. The script launched by the shell is without sh, but even if i wrote this in the cron or not, it doesn't work. I forgot to say that I installed the Java runtime, because on Lion isn't installed within the OS. –  Nopster Nov 5 '11 at 16:44
    
Can you check if cron itself is working? Have you edited it with crontab -e? –  slhck Nov 5 '11 at 17:19
    
Sure, tested it and it works, the crontab -e results list the right entry. The bat file is processed at the right time, but the backups are 0 bytes. –  Nopster Nov 5 '11 at 17:39
    
That leads me to believe that there's a problem with the backup application itself. What is that, even? Backupper.jar? You should probably debug it and see why the files are just 0 bytes. –  slhck Nov 6 '11 at 15:14

1 Answer 1

I'd do it the OS X way and use launchd instead of cron. You do this by writing a LaunchAgent. That's basically a .plist in the /Library/LaunchAgents or ~/Library/LaunchAgents that tell launchd what script to run and what the trigger for running the script should be.

launchd allows you to control whether the script should be run by the logged in user or by root.

Lingon.app is a nice way of getting started with and managing LaunchAgents.

The Apple Developer Connection man page might also help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.