1833536 Members
3130 Online
110061 Solutions
New Discussion

Re: cron and .netrc

 
Vishwa
Occasional Advisor

cron and .netrc

I have a script that uses .netrc to automate some FTP processes. It works
well when run manually on the command line, but it chokes on the login
when run as the same user from cron. It appears to not be using the .netrc
login info at all. Anyone have an idea how to get around this? If there is
a way to reprogram the shell script to accomplish the same task it can be
done as well.
When going gets tough, upgrade. © Murphy.
11 REPLIES 11
Sanjay_6
Honored Contributor

Re: cron and .netrc

Craig Rants
Honored Contributor

Re: cron and .netrc

Also make sure that your have referenced all the command in your script as absolute paths. cron is a little different that running scripts manually. If it continues to fail, then pipe the output of the cronjob into an output file and see what happens, maybe even uses /bin/sh -x in the first line.

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Mark Greene_1
Honored Contributor

Re: cron and .netrc

keep in mind that cron does not execute either /etc/profile nor the .profile for the user, and any environment variables and the PATH you need has to be setup in the script for cron to see. Also, make sure the permissions on the .netrc file are 500

HTH
mark
the future will be a lot like now, only later
Vishwa
Occasional Advisor

Re: cron and .netrc

Thanks for the replies.

Well, the problem that I currently have is that the .netrc file resides under $HOME (i.e., /home/www, www is the account for which the cron is setup). The script resides under the same user's file system.

Cron is not recognizing the .netrc file under the $HOME. When the script is manually executed, .netrc file is considered and ftp works fine.

How do we make the cron to use the .netrc file ?.
When going gets tough, upgrade. © Murphy.
Steve Steel
Honored Contributor

Re: cron and .netrc

Hi


Could you show us your script.

Especially the connection to the other system.


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Volker Borowski
Honored Contributor

Re: cron and .netrc

Hi,
did you try to

export HOME=path_to_.netrc_dir

Volker
Darrell Allen
Honored Contributor

Re: cron and .netrc

Hi,

Are you running the ftp script from www's crontab? Or are you running it from root's crontab (su'ing to www)?

It will work if you use www's crontab but "su - www -c ftpscript" in root's crontab is going to fail. man netrc says:

If the .netrc file contains password or account information for use other than for anonymous ftp, its owner must match the effective user ID of the current process. Its read, write, and execute mode bits for group and other must all be zero, and it must be eadable by its owner. Otherwise, the file is ignored.

I think that may be your problem. I don't know how to correct your issue other than to allow www to run cron (/usr/lib/cron/cron.allow).

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Sebastian Galeski_1
Trusted Contributor

Re: cron and .netrc

Hi as i remember ,in past i have a problem with useing .netrc in script. Yhe problem was in permition to this file it should be 600.

regards Seba
Vishwa
Occasional Advisor

Re: cron and .netrc

Thanks for the replies. The problem still exists.

* The mode of .netrc file is 600.

* The script is being executed by www via cron (not root).

I am attaching an extract from the actual script which contains the ftp part.

When going gets tough, upgrade. © Murphy.
Mark Greene_1
Honored Contributor

Re: cron and .netrc

add the "-i" option to this line:

error=`ftp $REMOTE_HOST <$TMP_FTP_COMMAND_FILE`

after ftp like this:

error=`ftp -i $REMOTE_HOST <$TMP_FTP_COMMAND_FILE`

this turns off interactive processing of the ftp. Also, keep in mind that the value of "error" will only be the exit value of ftp, and not at all reflective of any errors during the ftp session.

HTH
mark
the future will be a lot like now, only later
Vishwa
Occasional Advisor

Re: cron and .netrc


Thanks, but -i dint solve the problem.
When going gets tough, upgrade. © Murphy.