-   Linux - Software (
-   -   Command not working in cron job, but works fine in root (

Roosta21 11-14-2007 10:43 AM

Command not working in cron job, but works fine in root
Hi I am running the jailkit which creates a chroot environment and chroots users.. The jail command works fine in command line.. but when i attempt run it in a cron it does not work/jail correctly

the cronjob is here

*/1 * * * *  /usr/sbin/jk_jailuser -v -m -j /var/www/vhosts/ unn_testjail5 >> /tmp/outputnew.log 2>&1
and below is the output


sh: usermod: comnd not found
adding user unn_testjail5 to /var/www/vhosts/ with shell /usr/sbin/jk_lsh
adding group unn_testjail5 to /var/www/vhosts/
modify user unn_testjail5; dir /var/www/vhosts/ and shell /usr/sbin/jk_chrootsh
failed to execute usermod -d /var/www/vhosts/ -s /usr/sbin/jk_chrootsh unn_testjail5
failed to modify user unn_testjail5
Moving files from /home/unn_testjail5 to /var/www/vhosts/
Creating directory/var/www/vhosts/
Copying /home/unn_testjail5/.bashrc to /var/www/vhosts/
Copying /home/unn_testjail5/.bash_profile to /var/www/vhosts/

I seems that the usermod is the problem but im not sure how to solve the problem

Tinkster 11-14-2007 11:06 AM

Is it called from with the script? Use the full path
in the script, not just the name.


Roosta21 11-14-2007 11:21 AM

The above command was in a perl script that didn't jail the user properly when running form a cron.. (although the script jailed the user fine if it was run from the command line) I then took the command in question out and tried to run it individually in the crontab

*/1 * * * * /usr/sbin/jk_jailuser -v -m -j /var/www/vhosts/ unn_testjail5 >> /tmp/outputnew.log 2>&1

and it produced the above errors..

Im newbie could you expand on what you were saying

Tinkster 11-14-2007 11:25 AM

Well ... since there's no mention of usermod in the cron-command
I'm assuming that jk_jailuser is a script. Now if you execute a
script from cron chances are high that the path doesn't match the
path in your login-shell. To mitigate that I suggest that you
edit the script and replace the spot where usermod is invoked with
a "magic incantation" that uses the full path to usermod.

Alternatively you could modify crons settings to be like the root
environment settings. But method one is cleaner (and safer).


Roosta21 11-22-2007 08:08 AM

Brilliant that worked great i added the path to the cron job.. and it all jails fine now through the cron

All times are GMT -5. The time now is 11:17 AM.