Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
Did you make your script executable? –  troylatroy Jan 8 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 8 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 8 at 22:24
add comment

3 Answers 3

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.

share|improve this answer
add comment

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)"
share|improve this answer
    
I'm using ubuntu server so it'll not work –  user2702899 Jan 8 at 19:35
    
Right you are. I guessed you were the more traditional desktop user. –  Marc Jan 8 at 21:01
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.