Crontab in raspberry pi does not run a very simple script

I am new to Linux, and I struggled with this problem for a while in my Raspberry Pi and was not successful.

First I wrote a simple script in the /home/myfile.shfollowing way:

#!/bin/bash
clear
echo "hi"

Then I did sudo chmod 755 /home/myfile.shto grant permissions.

And finally, I changed crontabwith crontab -e:

# some comments ...
* * * * * /home/myfile.sh

Problem:

When I run the script manually, it works fine, but when I set the above line to crontab, nothing happens. What am I doing wrong?

+4
source share
3 answers

, , , :

, crontab (/etc/crontab) crontab (crontab -e).

,

/etc/crontab crontab.

/etc/crontab :

# m h dom mon dow user      command
*   *  *   *   *  someuser  echo 'foo'

crontab -e 'crontab'.

crontab -e :

# m h  dom mon dow  command
*   *   *   *   *   echo 'foo'

, crontab .

+1

:

* * * * * /home/myfile.sh > output_file.txt

, .

Cron , .


Edit

crontab -e , crontab. , ( , ). , cron :

* * * * * /home/myfile.sh > /home/<username>/output_file.txt

, .

, crontab /etc/crontab

, cron, . /etc/rsyslog.conf or /etc/rsyslog.d/50-default.conf , , :

cron.*                         /var/log/cron.log

rsyslog cron:

sudo service rsyslog restart
sudo service cron restart

, cron .

+4

Cron jobs return stdout and stderr by default email, so you need to check your test there.

There is no mail client / agent in the standard scheduled distribution, so you need to install it, for example:

sudo aptitude install bsd-mailx

and you can check local emails with the command mail.

Typically, cron jobs do not return any output, redirecting all this to a log file.

+1
source

Source: https://habr.com/ru/post/1624797/


All Articles