PDA

View Full Version : cronjob only completes half of command


mark1491
08-08-2006, 10:05 PM
I have a cron job setup on one of my servers users, and have tested it in the shell and it works fine. But now when I do a cronjob

I put this command in the command part of the cron setup for example with test.com:

DATADIR="/home/test/domains/test.com/public_html/data/"; STOREFILE="/testcron/cronjobhumor/newmedianame.txt"; OLDNAME=$(head -1 $STOREFILE); NEWNAME="media"$(stat -c %Z $DATADIR$OLDNAME); mv $DATADIR$OLDNAME $DATADIR$NEWNAME; echo $NEWNAME > $STOREFILE;


But when I look at the log I only get this out of the command from above, it stops just before %


Aug 8 23:04:01 server177 crond[17486]: (test) CMD (DATADIR="/home/test/domains/test.com/public_html/data/"; STOREFILE="/testcron/cronjobhumor/newmedianame.txt"; OLDNAME=$(head -1 $STOREFILE); NEWNAME="media"$(stat -c

Do I need to have something other than the %, and if so what would that replacement be

Thanks in advance
Mark

toml
08-09-2006, 09:16 AM
Try escaping it with a backslash (\), shells can be pretty frustrating when using special characters. Don't know if it will help, but that is the first thing I would try.

mark1491
08-09-2006, 10:51 AM
I tried changing the (%) to a (\) and it didn't work, is that what you meant when you said:

Try escaping it with a backslash (\)

Thanks for helping let me know if you have any other suggestions

Thanks,
Mark

toml
08-09-2006, 10:52 AM
No, escaping means you make a '%' into '\%' so that the shell doesn't try to exapand or interpret the character as something else.

mark1491
08-09-2006, 11:29 AM
It worked that time with this command:

DATADIR="/home/test/domains/test.com/public_html/data/"; STOREFILE="/hotrankercron/cronjobhumor/newmedianame.txt"; OLDNAME=$(head -1 $STOREFILE); NEWNAME="media"$(stat -c \%Z $DATADIR$OLDNAME); mv $DATADIR$OLDNAME $DATADIR$NEWNAME; echo $NEWNAME > $STOREFILE;

This time the cronjob log shows the whole command there!!, but doesn't show the Z after the % ?????


DATADIR="/home/test/domains/test.com/public_html/data/"; STOREFILE="/testcron/cronjobhumor/newmedianame.txt"; OLDNAME=$(head -1 $STOREFILE); NEWNAME="media"$(stat -c % $DATADIR$OLDNAME); mv $DATADIR$OLDNAME $DATADIR$NEWNAME; echo $NEWNAME > $STOREFILE;


The Z is missing from the cron job log now, which makes the command not work still??

Thanks for helping toml, let me know if u can think of anything else!

Mark