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'd like to have a simple bash script run (regardless of whether anyone is logged in or not) akin to putting it in /etc/cron.daily/ on Linux, but on Mac OS X Mountain Lion 10.8.4. If it's possible, how? All it needs to do is copy (and maybe bzip) a file.

share|improve this question
1  
cron should run without being logged in. cron works the same way anywhere. –  Journeyman Geek Aug 16 '13 at 15:35
1  
Try a crontab -e. Create a job to touch a file in in a few minutes. Log out. Wait those minutes. Check if the file has been created. (Optionally: remove the now useless cron job :) ) –  Hennes Aug 16 '13 at 15:39
    
you don't have to be logged in but the computer does need to be in the active mode, meaning not closed –  amphibient Aug 16 '13 at 15:54

1 Answer 1

Using cron, you can edit the superuser's crontab with for example EDITOR=nano sudo crontab -e. When I tried adding a line like * * * * * say aa, the say command was run even after I logged out to the login window.

Using launchd, save a property list like this as for example /Library/LaunchAgents/test.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>test</string>
  <key>ProgramArguments</key>
  <array>
    <string>say</string>
    <string>bb</string>
  </array>
  <key>StartInterval</key>
  <integer>10</integer>
</dict>
</plist>

Then run sudo chown root /Library/LaunchAgents/test.plist and sudo launchctl load /Library/LaunchAgents/test.plist. The say command scheduled by launchd was also run when I logged out to the login window.

share|improve this answer
    
If I set the script to run while I'm logged in, it seems to work, but not when I'm logged out. Also, I can't find any entry in the log for it to see what went wrong. –  Lido Aug 30 '13 at 9:48
1  
Both methods worked for me when I tried logging out to the login window. If you mean the cron log, you can enable logging by editing com.vix.cron.plist. If you mean launchd, you can save the stderr or stdout of the program to a log file by adding a StandardErrorPath or StandardOutPath key. See man launchd.plist. –  Lri Aug 30 '13 at 10:33

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.