0

simple question:

10 4 * * * rm -rf ~/code/rehlds/build/ && ~/code/rehlds/build.sh --compiler=gcc --jobs=4 > /dev/null 2>&1

I checked an there is no /build folder which indicates that the build.sh did not execute.

crontab -e

10 4 * * * rm -rf ~/code/rehlds/build/ && ~/code/rehlds/build.sh --compiler=gcc --jobs=4 > /dev/null 2>&1

pgrep cron 658 1232359

so here I can see it was run sudo grep CRON /var/log/syslog Dec 8 04:10:01 xxxx CRON[1190963]: (xxx) CMD (rm -rf ~/code/rehlds/build/ && ~/code/rehlds/build.sh --compiler=gcc --jobs=4 > /dev/null 2>&1)

my job ran, but no compiling, that cronlog file is empty.

CMD (./code/rehlds/build.sh --compiler=gcc --jobs=4 &> ./cronlog)

eetzt
  • 1
  • 1
  • Does the logs have any relevant errors? – vidarlo Dec 08 '22 at 11:51
  • With all output redirected to/dev/null there most probably are no logs. – Gerald Schneider Dec 08 '22 at 11:53
  • Set output to log file, not `dev/null` and run again – Romeo Ninov Dec 08 '22 at 11:58
  • `10 4 * * * rm -rf ~/code/rehlds/build/ && ~/code/rehlds/build.sh --compiler=gcc --jobs=4 > ~somelog` like this? will it create this `somelog` if not existing? – eetzt Dec 08 '22 at 11:59
  • No, use something like: `>/full/path/log 2> /full/path/err` to generate log for STDOUT and for STDERR. And use absolute paths – Romeo Ninov Dec 08 '22 at 12:08
  • not even this works for 5min `* * * * * touch ./testfile &> ./testlog ` – eetzt Dec 08 '22 at 12:32
  • ok now i found out that if you are working with 2 bash sessions and save in nano, then the file is not written, only if you close it... – eetzt Dec 08 '22 at 12:44
  • 3
    Does this answer your question? [Why is my crontab not working, and how can I troubleshoot it?](https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it) – diya Dec 08 '22 at 12:50
  • why does this log output not work? `somecmd > ~/rehldslog 2>&1`. in the logs i can see `(CRON) info (No MTA installed, discarding output) ` and somecmd did not run – eetzt Dec 10 '22 at 12:31

1 Answers1

0
  1. if you work with 2 bash session, you must not only save the file with nano, but close it, only then is the crontab added.

  2. when executing the build.sh I must first cd into that directory otherwise error:

$ ./code/rehlds/build.sh --compiler=gcc --jobs=4 CMake Error: The source directory "/home/cs2" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI. make: *** No targets specified and no makefile found. Stop.

I found that out by manually executing this command

correct command:

10 4 * * * cd ./code/rehlds && rm -rf ./build && ./build.sh --compiler=gcc --jobs=4 > /dev/null 2>&1

eetzt
  • 1
  • 1