Fork me on GitHub
#babashka
<
2022-10-30
>
walterl21:10:10

I'm running a script with bb via cron, but not seeing any output. Neither in system logs (`journalctl -f`), nor when redirecting output to a file (`bb script.clj &> script.log`). Also not for printlns, nor when logging with clojure.tools.logging or timbre. Any ideas why this is?

walterl21:10:14

Do I need to do something to enable output on "detached" tty's like cron?

walterl21:10:35

I know the script runs, because spitting to a file works.

walterl21:10:03

All combinations work as expected when running the script in the same way from a terminal

borkdude21:10:38

Does output work when you're using something different than bb, eg. bash?

walterl21:10:41

This works, yes: * * * * * echo "from cron" >> ~/crontest.log

walterl21:10:48

(from crontab)

borkdude21:10:30

what if you call an external bash script?

walterl21:10:05

I see where you're going with this... let's see...

walterl21:10:22

Ha! It works! 🎉

walterl21:10:41

Why would running bb from a bash script behave differently than when it's executed by cron?

borkdude21:10:47

ehm, well, I actually meant executing a bash script that did that echo, but glad it works, I have no idea why this works ;)

walterl21:10:57

Still, thanks! 🙌

🙌 1
respatialized15:10:08

@UJY23QLS1 cron runs in a different environment to ordinary bash, so if you want to rely on bb for cron tasks it is probably worth investigating how your crontab's environment differs (e.g. a different $PATH) from your standard bash environment. https://stackoverflow.com/questions/29103763/ubuntu-cron-shebang-not-working

walterl15:10:20

Yeah, my best guess at an explanation is along those lines: somehow stdout/stderr isn't set up and inherited by cron jobs in the same way as they are in bash. Something else that crossed my mind is that it could be Java that does some similar stdout/stderr voodoo (which I vaguely recall having bumped into before), and that bb inherited those oddities from there. Unfortunately I don't have the bandwidth to investigate further.