I tried this script to be called by cron / Scheduled Tasks, but logger does not write anything into syslog. Started from CLI the output of the script is written into syslog. I did run out of ideas to find the cause ...
#!/bin/sh
logger "example"
logger -p notice -t example "example notice"
logger -p err -t example "example notice"
Output:
Fri May 8 00:23:26 2020 user.notice root: example
Fri May 8 00:23:31 2020 user.notice example: example notice
Fri May 8 00:23:40 2020 user.err example: example notice
More information:
# logger --help
BusyBox v1.30.1 () multi-call binary.
Usage: logger [OPTIONS] [MESSAGE]
Write MESSAGE (or stdin) to syslog
-s Log to stderr as well as the system log
-t TAG Log using the specified tag (defaults to user name)
-p PRIO Priority (numeric or facility.level pair)
I forgot, the output in syslog is:
Fri May 8 00:54:00 2020 cron.info crond[11630]: USER root pid 12247 cmd /etc/crontabs/test.sh
in a cron script, the path of all called programms must be qualified, so "logger "example" does not work, it has to be chaned to "/usr/bin/logger "example" to run in a cron script. But still it does not generate output into syslog.
No it doesn't have to be qualified. My crons logs are running fine. I just double-checked it for you.
From a script called by cron:
/usr/bin/logger "testbin"
logger "testdirect"
Syslog output:
Fri May 8 01:03:00 2020 user.notice root: testbin
Fri May 8 01:03:00 2020 user.notice root: testdirect
Both direct and fully qualified work. It's /usr/bin/logger by the way for logger.
Here's why the logger command doesn't have to be qualified:
# echo $PATH
/usr/sbin:/usr/bin:/sbin:/bin
As you can see, the root user has the /usr/sbin, /usr/bin, /sbin, and /bin paths in its PATH environment variable. I can see from your log output that you're also running the script as root (technically, cron is running as root, and therefore also the script). Since the logger binary is located in /usr/bin, and the /usr/bin folder is mentioned in the PATH environment variable, it doesn't need to be fully qualified in order to work.
great !!
I erased anything else in the test-script, now it gives back the output into syslog.
I will erase line by line, I guess some line generates an error
exec rights were OK.
Hehe, always run the script itself directly in the shell to see errors. Don't debug in cron, or redirect the output in a cron to a file for debugging purposes.