0

According to this site I set up cron to execute a script for me, first just trying to get it to work with cat before doing the actual work I need to do (actual work will need root priviliges so I did everything as root to make my life easier later):

me> sudo su
root> crontab -e

Edited the file as follows, leaving a blank line at the end:

SHELL=/bin/bash
#which cat outputs /bin/cat
PATH="/bin"

# execute this every minute, if it works, change cat to my script
1 * * * * cat /home/me/source.txt 1> /home/me/destination.txt

According to this SO question, restarted the cron service to be sure it loads changes after saving the file and exiting the editor:

root> service cron restart

And then waited for a few minutes. Nothing happened. Then restarted the computer. Again, nothing. Where did I do it wrong?

1
  • 1
    Did you wait till the 1st minute of the hour? Commented Nov 20, 2018 at 19:38

1 Answer 1

3

Your crontab is running at 1st minute of every hour. To run every minute you have to configure like this.

* * * * * cat /home/me/source.txt 1> /home/me/destination.txt
3
  • Thanks, didn't think that through very well. My actual task won't need to run every minute, every 15 minute is enough. Is there a shorthand for that, or do I have to copy the same command 4 times with 0 * * * *, 15 * * * *, etc.? Commented Nov 20, 2018 at 20:16
  • 1
    */15 * * * * cat /home/me/source.txt 1> /home/me/destination.txt. Commented Nov 20, 2018 at 20:21
  • 2,17,32,47 also works. I try not to kick a lot of things off in synchronisation. I suspect 2-59/15 is equivalent also. Commented Dec 19, 2019 at 18:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.