dcron icon indicating copy to clipboard operation
dcron copied to clipboard

A way to output a job's output to stdout?

Open x-yuri opened this issue 2 years ago • 8 comments

That would be most welcome for running dcron in a docker container. Then there'd no need to set up mail, and docker logs could be used to inspect what's going on.

x-yuri avatar Sep 28 '21 10:09 x-yuri

@x-yuri , I have the same issue, did you find a way to output job's output to stdout? Or are you using another cron?

ttionya avatar Jun 28 '22 06:06 ttionya

@ttionya I didn't find a way to make dcron output to stdout. I've found slicd, which is an old unsupported piece of software, but it works. There's also this gist, but I'm not sure if it works. UPD Oh, there's my comment there, so supposedly it does, but with rsyslog.

x-yuri avatar Jun 28 '22 07:06 x-yuri

...And even under Alpine Linux w/o rsyslog.

x-yuri avatar Jun 28 '22 07:06 x-yuri

Actually, even with dcron it seems to work under Alpine Linux.

x-yuri avatar Jun 28 '22 08:06 x-yuri

Also looking for a way to achieve this, possibly without any extra software. I don't see the point of installing and configuring a mail server just for logging the output of a couple scripts, it's easier and more practical to have all the logs in one place

KingDuckZ avatar Jun 28 '22 11:06 KingDuckZ

@x-yuri , Thanks for the quick reply, I saw your reply a few hours ago but I was in a hurry to go to the hospital so I didn't reply in time.

My current cron configuration is * * * * * bash xxx.sh > /dev/stdout, but there is no output from dcron (busybox cron works fine), I will try to change it to /proc/1/fd/1 and test if it works.

My requirement is simple, execute the script regularly and docker logs can see the stdout of the script. I think it's a good idea to write the stdout of the script to a file and start crond in the background, and docker's entrypoint executes tail -f to listen for changes in the contents of the file. I'll try it out and post the results here later.

ttionya avatar Jun 28 '22 13:06 ttionya

I'll try it out and post the results here later.

Both methods, > /proc/1/fd/1 and redirecting the output file to a file and then reading the contents of the file via tail -f will print the stdout of the script properly. @x-yuri @KingDuckZ

I would choose /proc/1/fd/1 because it is very simple.

ttionya avatar Jun 28 '22 13:06 ttionya

Thanks but I switched to cronie and configured it to run with -s -m off which does just what I want

KingDuckZ avatar Jun 28 '22 17:06 KingDuckZ