ThN ThN - 4 months ago 34
Bash Question

How to run Bash Script in Crontab on Raspbian?

I have gone through all sorts of answers and replies up and down the Internet and nothing to seem to work for me. I want to simply run a bash script every minute using CRONTAB on Raspberry PI on Raspbian.

I have a script called and I simply entered into crontab as follows:

1 * * * * root bash /home/pi/

What am I doing wrong?


I'm not sure where the 'root' part comes from, but I'm guessing you're wanting to run the script as root? If so, you need to put an entry into the root crontab, do so by running:

sudo crontab -e

This will open up the root user crontab for editing, anything run from said location will run with root priveleges.

Insert the following line:

* * * * * bash /home/pi/

That should do it :) The 1 in your script actually means 'run at 1 minute past the hour' and thus in your case, 1 minute past every hour - easy mistake! Replacing it with a * means every minute.

The syntax is:

minute - hour - day of month - month - day of week - command 

Additionally, if you make your script executable, like so:

sudo chmod +x /home/pi/

You can omit the 'bash' command, and simply use:

* * * * * /home/pi/

And unless you're using the two lines at the top for something in particular, you can omit those too.

For clarity, Barmar's comment on my original post:

In per-user crontab files you don't put the username. But in /etc/crontab you do.