April 16th, 2013, 01:27 AM
-
Script shell working manually, but not with cron
Hi,
I just did a script in the purpose to save all directory from a specific one's (/var/www/html ).
The script works perfectly when launched manually, but not at all when it's the cron that launch it automatically =/
here's the script =>
Code:
for SITE in `ls $MYDIR | grep -v "chroot\|default"` ; do
if [ -d $MYDIR${SITE} ]; then
echo 'here, before tar '$MYDIR${SITE} >> log.txt
tar -czvf ./${SITE}.tar.gz $MYDIR${SITE}
fi
done
I just have no idea what's going on, i checked into the log.txt, the path and the directory name are good, but, it looks like only one directory has been zipped, and nothing else happen,...
Here's what i got from the log =>
Quote:
here, before tar /var/www/html/my_sitename
Hoping someone could give me a hint on this issue,
Hurin
PS: sorry for my low english level ^^
April 16th, 2013, 06:06 AM
-
A couple of things spring to mind - the environment in use (there are differences between your user environment and the one cron providesn - maily in PATH but also in what shell is used). Where does the variable $MYDIR come from?
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
April 16th, 2013, 11:21 AM
-
April 18th, 2013, 06:31 AM
-
No idea why appending the stdout and stderr from the tar command is now making the (I presume) loop process more directories! What happens if you run the revised script manually?
<edit>
Now, having tried the code (and giving MYDIR a suitable value), I can really see no reason as the original code works fine for me - both run manually and via cron.
</edit>
Last edited by SimonJM; April 18th, 2013 at 08:15 AM.
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc