LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Command not working in cron job, but works fine in root (http://www.linuxquestions.org/questions/linux-software-2/command-not-working-in-cron-job-but-works-fine-in-root-599595/)

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
Code:

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

Code:

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

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.


Cheers,
Tink

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/mydomain.co.uk/web_users 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).



Cheers,
Tink

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 05:05 AM.