Koozali.org: home of the SME Server
Obsolete Releases => SME Server 7.x => Topic started by: loejf on June 08, 2009, 10:32:16 AM
-
Hi.
I have made at script /root/script/myscript.sh
with chmod 755
And in crontab I have added:
00,30 * * * * root /root/scripts/myscript.sh
and /var/log/ shows
Jun 8 10:30:01 ydun crond[4817]: (root) CMD (/root/scripts/myscript.sh)
But the problem is, the scripts does not do the work, but if I run it manually, it does.
Any suggestions?
Loejf
-
You might try using complete specifications for all executables in your script - that is, use /bin/program or /usr/bin/program instead of simply running program and trusting PATH to be correct.
Figure out a way to make your program more informative, then you'll get more info in the log files...
Make sure (with permissions of 755) that the script is owned by the user "root"
-
Hi.
Right now the trial script only runs an echo, and pipe this into a logfile.
And when I run it manually, it works.
The script is owned by root, and has permissions 755, including the folder.
Could it be something like, when cron runs, is does not use the root environment, but its own ??
Loejf.
-
Hi. I have tried to follow this way to do it:
mkdir /etc/e-smith/templates-custom/etc/crontab/
vim /etc/e-smith/templates-custom/etc/crontab/fileprocessor.cron
#This text was then added to the file:
#FILEPROCESSOR SCRIPT
00,30 * * * * root /root/FILEPROCESSOR/fileprocessor.sh
/sbin/e-smith/expand-template etc/crontab
more /etc/crontab - just to verify your new entry is there, then
service crond restart
-
Hmmmm.
It doesn´t make any difference.
Same result.
-
loejf, as mmccarn told you, you'd use full path to executable files in your script.
try (example, adapt to your needs)
...
MV='which mv'
...
$MV oldfile newfile
hth
ciao
Stefano
-
Hi.
Yes, but I do that.
The only executable file is "fileprocessor.sh", and it is located "/root/FILEPROCESSOR/fileprocessor.sh", and that is what I have added to Cron.
Do I misunderstand something ?
Loejf.
-
Do I misunderstand something ?
yes :-)
we are talking about instrunctions into fileprocessor.sh :-)
Ciao
Stefano
-
Do I misunderstand something ?
Yes, since you only use echo (you stated earlier) make sure you do something like this:
#!/bin/sh
/bin/echo "Hello world!"
instead of
#!/bin/sh
echo "Hello world!"
To find the full path to a executable (within your root path on the CLI) you can use the 'which' program, e. g.:
which echo
should give you something like this:
[root@smetest ~]# which echo
/bin/echo
[root@smetest ~]#
There are ways to define the path inside scripts as well using:
PATH=/usr/bin:/usr/sbin:.
See for instance: http://blog.spikesource.com/crontab.htm
-
Hi.
I did add the following to the script:
USER=root
HOME=/root
LOGNAME=root
PATH=/sbin/e-smith:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
SHELL=/bin/bash
And it did it. So now it works.
Thank you very much for your help.
But it seems unnecessary difficult to get working ??
Loejf.
-
But it seems unnecessary difficult to get working ??
That might be to you, you could also have just replaced echo by /bin/echo like also suggested, you did a little bit more than needed.
Keep in mind that cron jobs run in a chroot environment with minimal settings for security purposes as well, therefore amongst some other things a path is not set. I would advice you to not set a path and use the full filename for programs you invoke from your script or reduce the path environment variable to it's bare minimum as it is a little (too) extended at the least if I look at it.