Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script works from command line but not cron 2

Status
Not open for further replies.

siswjh

MIS
Dec 6, 2001
63
US
I have a script that works fine when it is run from the command line but when I put it in cron this is what I get.

/export/home/siswjh/korn/zipthis

produced the following output:

zip warning: name not matched: dskusage

zip error: Nothing to do! (korn.zip)
zip warning: name not matched: freespace

zip error: Nothing to do! (korn.zip)
zip warning: name not matched: ftpD

zip error: Nothing to do! (korn.zip)
zip warning: name not matched: ftpacbs

zip error: Nothing to do! (korn.zip)
zip warning: name not matched: logins_nopass

zip error: Nothing to do! (korn.zip)
zip warning: name not matched: message

zip error: Nothing to do! (korn.zip)
zip warning: name not matched: moveas400

zip error: Nothing to do! (korn.zip)
zip warning: name not matched: performance

zip error: Nothing to do! (korn.zip)

This is the script.

HOME="/export/home/siswjh/korn"
AHOME="/export/home/siswjh/ftp"
filesndir=$(ls -l $HOME|nawk '{print $9}'|grep -v "ftppmag"|grep -v "zipthis")
for lines in $filesndir
do
zip korn $lines
done

When I run it command line this what I get.
root@detroit # zipthis
adding: dskusage (deflated 79%)
adding: freespace (deflated 54%)
adding: ftpD (deflated 68%)
adding: ftpacbs (deflated 69%)
adding: logins_nopass (deflated 51%)
adding: message (deflated 73%)
adding: moveas400 (deflated 35%)
adding: performance (deflated 67%)
It works fine. Does anybody have any clues?
Thanks
Jesse
 
hi,

one thing to check is are you in the direcvtory when you issue the zip . It probably can't find the file you want to zip so before the for loop , cd into the directory ($HOME)
and re-rty it.

 
Remember that scripts run from cron do NOT have a $PATH environment variable. You need to specify the actual location of your zip program.

From the commandline type: which zip
It will return something like: /usr/lib/zip

Modify your script to include that fully qualified path and executable.

Hope it helps. Einstein47
("For every expert, there is an equal and opposite expert." - Arthur C. Clarke)
 
1. Cron executions occur (usually) with a very minimal environment, so unless you provide things like environment variables, paths, etc., in the cron invocation, ... you don't get it.

For example, here a (long) crontab we use to provide an environment with a common user profile (sorry! it's big, long and ugly) Runs every Friday at 6am; sends output to log; errors to bitbucket:
00 06 * * 5 (. /home/forte3/.509profile; /forteenv/cm509/scripts/dailystartup -earch) > /forteenv/architecture/log/dailystartup.log 2>/dev/null


2. Also, don't see a shbang line in your scipt. Usually a #!/bin/[ksh|csh|sh|...] must be first line on your script, otherwise cron assumes /bin/sh

Hope this helps,

Hutch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top