Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using qsub within crontab?

Tags:

bash

cron

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.

like image 463
user1382685 Avatar asked Dec 11 '25 09:12

user1382685


1 Answers

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?)

like image 185
Keith Thompson Avatar answered Dec 14 '25 06:12

Keith Thompson