Issue
I'm new to Linux and I've been struggling with this issue for a while in my Raspberry Pi and had no success.
First I wrote a simple script in /home/myfile.sh
like this:
#!/bin/bash
clear
echo "hi"
Then I did the sudo chmod 755 /home/myfile.sh
to grant the permissions.
And finally I modified the crontab
using crontab -e
:
# some comments ...
* * * * * /home/myfile.sh
The problem:
When I run the script manually it works fine but when I set the above line in my crontab
, nothing ever happens. What am I doing wrong?
Solution
In order to show how I managed to solve my issue with the hope of helping others, Here I post it as an answer to my own question:
I got around the problem by using system-wide crontab (/etc/crontab
) instead of per user crontab (crontab -e
).
To clarify this,
/etc/crontab
is the system-wide crontab:
# m h dom mon dow user command
* * * * * someuser echo 'foo'
while crontab -e
is per user 'crontab':
# m h dom mon dow command
* * * * * echo 'foo'
Notice in a per user crontab there is no 'user' field.
Answered By - Bahman_Aries Answer Checked By - Marie Seifert (WPSolving Admin)