I'm trying to qsub a script within crontab. Within a crontab txt file, I tried:
0 1 * * * qsub /script.sh
The error I get is "/bin/sh: qsub: command not found." I've tried a bunch of similar iterations and looked around online without success. I'd appreciate any help.
Programs executed under cron run with a limited set of environment variables. In particular, since it doesn't read your shell startup files (.bashrc, .profile, .cshrc, whatever), it won't have your $PATH settings; $PATH is likely to be something simple like /usr/bin:/bin.
You can set the PATH for a single command like this:
0 1 * * * PATH=/directory/containing/qsub:/usr/bin:/bin qsub /script.sh
You can also set environment variables globally; such settings will apply to all commands executed from your crontab:
PATH=/directory/containing/qsub:/usr/bin:/bin
0 1 * * * qsub /script.sh
man 5 crontab, or see here, for more information on writing crontabs.
If you want to see just what the environment for a cron job looks like, you can temporarily add this line to your crontab:
* * * * * printenv > cron-env
Wait until the top of the next minute, then cat ~/cron-env -- and then remove that line from your crontab so it doesn't keep executing.
(Is your script really in the root directory? Why isn't it under your home directory?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With