I would like to execute a script on my machine every five minutes, even when I am not in front of my mac OS X Yosemite. Therefore, I would like to lock my session and shut off the screen while the computer stays active. How can I do that. I have tried with a crontab.

Let's say this is my script :

D=`date +%Y%m%d.%H%M`
echo "Hello" > "test_$D.txt"

and this is my crontab entry

*/5 * * * * /MyPath/script.sh > /MyPath/log

When I do this, and when I lock my session, or start the screen saver, the crontab doesn't execute, which mean that I need to keep my session and my screen open all day long. Is there a way to do what I want to do with a mac?

  • 1
    Cron jobs should execute even while the screen saver is running. Does the job execute correctly every 5 minutes while the computer is running? – nohillside Jan 24 '17 at 5:45
  • Actually, whenever you write a cron job, test it by running it directly. It's a good practice, you'll be sure it works before actually putting it in a cron. – Marc Carné Bori Jan 24 '17 at 15:00

Patrix got it right. I have made a mistake in my bash script, which caused error... Sorry for the post.

  • It's helpful if you post what your mistake was and what you did to fix it. As it stands, this is more of a comment than an answer. – Allan Jan 24 '17 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .