Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Dec 2007 19:17:10 +0700
From:      Supote Leelasuppakorn <pjn0211@hotmail.com>
To:        <freebsd-questions@freebsd.org>
Subject:   Re: Shell script in crontab cannot write files into FreeBSD's filesystem. (2nd evised version)
Message-ID:  <BAY102-W322FE42B7F377A7E36BC56B96E0@phx.gbl>
In-Reply-To: <BAY102-W1976C69F4C7E8D7BF09A64B96E0@phx.gbl>
References:  <BAY102-W1976C69F4C7E8D7BF09A64B96E0@phx.gbl>

next in thread | previous in thread | raw e-mail | index | archive | help


Hi list,

   Thanks, Derek. You're right. The date command must be the absulute path. Now it works.


Thanks for your best answer.

Pote

> 
>>Hi all,
>>
>>    Please anybody help me, I faced the problem with my "crontab".
>>I tried to run a shell script which will fetch webpage and save it to
>>a directory by using wget but after few minute I cannot see any file
>>in such directory
>>
>>    Below are content of shell script, my crontab and also
>>file's permission listing.
>>
>>##########################
>># Output of `crontab -l`
>>##########################
>>SHELL=/bin/sh
>>MAILTO=pjn
>>* * * * * . /home/pjn/parseGP/fetchPage.sh
>>
>>
>>########################
>># file: fetchPage.sh
>>########################
>>#!/bin/sh
>>TIMESTAMP=`date "+%Y%m%d-%H%M%S"`
> 
> You are assuming that date is in your path by the above statement.  Never
> assume you have a good path, unless you set it in your script file.  So,
> either setup the path you need or use absolute pathnames such as:
> TIMESTAMP=`/bin/date "+%Y%m%d-%H%M%S"`
> 
> 
>>LOGPATH="/home/pjn/parseGP/logs"
>>/usr/local/bin/wget --no-cache -a ${LOGPATH}/fetch.log -O
>>${LOGPATH}/${TIMESTAMP}.html http://www.blahblah.com
>>
>>
>>########################
>># Files' permission
>>########################
>>blahHost$
>>blahHost$ls -ltrd parseGP
>>drwxr-xr-x 3 pjn pjn 512 Dec 5 14:27 parseGP
>>blahHost$ls -ltr parseGP/
>>total 4
>>drwxr-xr-x 2 pjn pjn 512 Dec 5 15:11 logs
>>-rwxr--r-- 1 pjn pjn 226 Dec 5 15:21 fetchPage.sh
>>blahHost$ls -ltr parseGP/logs/
>>total 0
>>-rw-r--r-- 1 pjn pjn 0 Dec 5 15:14 fetch.log
>>blahHost$
>>
>>
>>
>>TIA
>>Pote
> 
> Make sure your script runs correctly outside cron, then test it from inside
> cron.  Add some echo statements so you can see what is executed, such as:
> #!/bin/sh
> TIMESTAMP=`/bin/date "+%Y%m%d-%H%M%S"`
> LOGPATH="/home/pjn/parseGP/logs"
> echo $(TIMESTAMP)
> echo $(LOGPATH)
> echo /usr/local/bin/wget --no-cache -a ${LOGPATH}/fetch.log -O
> /usr/local/bin/wget --no-cache -a ${LOGPATH}/fetch.log -O
> echo ${LOGPATH}/${TIMESTAMP}.html http://www.blahblah.com
> ${LOGPATH}/${TIMESTAMP}.html http://www.blahblah.com
> 
>          -Derek
> 
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BAY102-W322FE42B7F377A7E36BC56B96E0>