1

I'm trying to make crontab run a sh script every 5 minutes.

This is my root (sudo crontab -e) crontab setup:

*/5 * * * * /etc/test.sh

and this is the script:

#!/bin/bash
echo "time:$(date)"

EDIT: i've made it work by using the user crontab file (crontab -e) but I still need to run my script with administrative privileges...

  • Did you make your script executable? – troylatroy Jan 08 '14 at 19:18
  • 1
    Where do you expect the output of the echo command to go? The cron process does not run in a terminal (in particular it does not run in the terminal from which you invoked the crontab command). If you look in /var/log/syslog you will probably find a log entry confirming that the job did in fact run (provided the script is executable). – steeldriver Jan 08 '14 at 22:13
  • executable scripts shouldn't be kept in /etc - that folder is for configuration files. /usr/local/bin would be a much better choice. – ImaginaryRobots Jan 08 '14 at 22:24

3 Answers3

1

First make sure your script is executable! If so, it can also be because PATH is not set, have a look at this post and its replies:
Reasons why crontab does not work

Also my suggestion would be using cron.d instead of making a mess in crontab file.

hatef
  • 185
0

If you want a notification in a balloon at the upper right of youe screen where all the other notifications show up, try this command:

 notify-send "$(date)"
Marc
  • 9,980
0

This doesn't solve the problem the way you wanted to, but it just might git'r'done anyway.

PS1="(\$(date +%H:%M) $PS1"

That will put the time in hour:minute format into your shell prompt. Hit {Enter} on an empty prompt, get the time. Works just dandy on my servers.

K7AAY
  • 17,202