MacOS – Crontab and session locked

cronmacosscreen-lock

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 :

#!/bin/bash
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?

Best Answer

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