У меня чистая установка Ubuntu 18.04, и у меня возникают проблемы с получением задания cron для выполнения скрипта.
Crontab -l
содержит следующее:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/user/local/sbin:/usr/sbin:/home/rob/scripts
*/1 * * * * /bin/bash /home/rob/scripts/scan2.sh >> /home/rob/scripts/scan.log 2>&1
0 1 * * * /bin/bash /home/rob/scripts/trimdb.sh
0 1 * * * /bin/bash /home/rob/scripts/sortf.sh
Я могуубедитесь, что задание cron выполняется в правильное время в пределах /var/log/syslog
, как показано ниже, без каких-либо ошибок:
May 28 21:38:01 net CRON[1899]: (rob) CMD (/bin/bash /home/rob/scripts/scan2.sh >> /home/rob/scripts/scan.log 2>&1)
May 28 21:39:01 net CRON[1915]: (rob) CMD (/bin/bash /home/rob/scripts/scan2.sh >> /home/rob/scripts/scan.log 2>&1)
May 28 21:40:01 net CRON[1931]: (rob) CMD (/bin/bash /home/rob/scripts/scan2.sh >> /home/rob/scripts/scan.log 2>&1)
May 28 21:41:01 net CRON[1947]: (rob) CMD (/bin/bash /home/rob/scripts/scan2.sh >> /home/rob/scripts/scan.log 2>&1)
Однако, когда я проверяю службу cron, я вижу, что есть ошибка аутентификации:
May 28 21:46:01 net sudo[2146]: pam_unix(sudo:auth): conversation failed
May 28 21:46:01 net sudo[2146]: pam_unix(sudo:auth): auth could not identify password for [rob]
May 28 21:46:01 net CRON[2134]: pam_unix(cron:session): session closed for user rob
May 28 21:47:01 net CRON[2152]: pam_unix(cron:session): session opened for user rob by (uid=0)
May 28 21:47:01 net CRON[2153]: (rob) CMD (/bin/bash /home/rob/scripts/scan2.sh >> /home/rob/scripts/scan.log 2>&1)
May 28 21:47:01 net sudo[2164]: pam_unix(sudo:auth): conversation failed
May 28 21:47:01 net sudo[2164]: pam_unix(sudo:auth): auth could not identify password for [rob]
May 28 21:47:01 net CRON[2152]: pam_unix(cron:session): session closed for user rob
Сценарий отлично работает при запуске вручную.
Спасибо за помощь.
Содержимое файла scan.log:
sudo: no tty present and no askpass program specified
/home/rob/scripts/scan2.sh: line 43: grep: command not found
/home/rob/scripts/scan2.sh: line 1: date: command not found
/home/rob/scripts/scan2.sh: line 2: date: command not found
/home/rob/scripts/scan2.sh: line 3: date: command not found
/home/rob/scripts/scan2.sh: line 5: date: command not found
/home/rob/scripts/scan2.sh: line 6: date: command not found
/home/rob/scripts/scan2.sh: line 7: date: command not found
/home/rob/scripts/scan2.sh: line 41: grep: command not found