Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 1806  / 2 Years ago, sat, march 12, 2022, 12:14:26

im trying to run a script stored in my home directory via crontab, but it's not working. The CRON log just says this every time it's running:


Sep  3 18:30:01 backup CRON[6778]: (root) CMD (/home/hannes/script > /tmp/yc.log)
Sep 3 18:30:01 backup CRON[6777]: (CRON) info (No MTA installed, discarding output)

Crontab:


*/1 * * * * /home/hannes/script > /tmp/yc.log

If I try to add the .sh file extension, it does not change anything.
The yc.log file stays empty.


This is the Script I'm trying to execute (Works fine if I run it manually):


#!/bin/sh
cp -r -p mnt/main-nas/PATH-TO-FILE mnt/backup-nas/01/temp/server
zip -r mnt/backup-nas/01/1.19_Test.`date +%d.%m.%Y_%H.%M.%S`.zip mnt/backup-nas/01/temp/server
rm -r mnt/backup-nas/01/temp/server

Any help is appreciated! :)


More From » cron

 Answers
3

Your script is actually running... but it's erroring out somewhere.
And since you don't capture stderr output, stderr is sent via cron to the user who's running the script locally. (And failing as well)


The root cause is this: your script only redirects stdout to files. A lot of failing scripts and programs, however, use stderr to output their error messages. You need to catch that by adding 2>&1 to the end of your command line that cron executes, which will also capture stderr and log errors to your file as well.


Because you didn't catch it previously, stderr was being delivered via mail to root - but because you don't have a local MTA (Mail Transfer Agent aka Local Mail Transport Protocol (LMTP) server) for local delivery, you got those cron errors. With the stderr capture you will now see errors and why your script(s) haven't run properly.


Once you have the error output in your logs, you can further debug your script to determine what needs to be done to 'fix' things.


[#260] Sunday, March 13, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
finatch

Total Points: 49
Total Questions: 106
Total Answers: 94

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
finatch questions
Sun, Jun 26, 22, 07:28, 2 Years ago
Mon, May 17, 21, 15:25, 3 Years ago
Wed, Jun 8, 22, 02:40, 2 Years ago
;