I'm having some trouble with my cron job, and I'm not exactly a crontab expert. Here's the situation:
I've set up the job to use the `zsh` shell, and I've defined a couple of variables in my minimal `.zshenv` and `.zshrc` files. The cron job is supposed to run every minute and simply source these two files and then log their values. However, my log file isn't being created at all. It seems the job only runs when I source either the `.zshenv` or `.zshrc` individually, but when I try to run them both with the command `. ${HOME}/.zshenv && . ${HOME}/.zshrc`, it fails. Any ideas on what might be causing this issue?
3 Answers
It seems like the problem might be that the `$HOME` variable isn't set correctly when the cron job runs. This could cause the sourcing of `.zshenv` to fail, and since you’re using `&&`, if the first command fails, the second one won’t run either.
Most issues with cron jobs, especially when they run fine in a terminal, are related to PATH or environment variables. You should check if `$HOME` is set as expected. Also, instead of using the dot (`.`) to source your files, try using `source`, which is clearer and might reduce errors.
The first part of your command does a source on a dot, which is interpreted as a directory and will fail. This error stops the rest of your commands due to how `&&` works, halting everything if one fails.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String