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...

3
  • Did you make your script executable?
    – troylatroy
    Jan 8, 2014 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). Jan 8, 2014 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. Jan 8, 2014 at 22:24

3 Answers 3

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.

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)"
2
  • I'm using ubuntu server so it'll not work Jan 8, 2014 at 19:35
  • Right you are. I guessed you were the more traditional desktop user.
    – Marc
    Jan 8, 2014 at 21:01
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.

You must log in to answer this question.

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