Using FTP from cron with .netrc

Thad P Floryan thad at cup.portal.com
Fri Jan 11 02:53:40 AEST 1991


kmeek at cti1.UUCP (Kevin Meek) in <366 at cti1.UUCP> writes:

	I am trying to send files from a central machine to 
	another file on the remote host.

	What I've done is create a .netrc directory in my home directory
	with the machine name and password.

	then I run the following shell script
	[...]
	This script works fine when I execute it from the prompt 
	but when I try to run it from my cron I get the following
	errors.  
	[...]
	It isn't using the .netrc??  
	I tried setting the $HOME variable and even running an
	su -c username "shellscript" in the cron so my .profile
	would be run but still no dice!.

	Any suggestions  -- why won't ftp work from cron.

	I am working on an AT&T 3B2600G running system V ver 3.2.2

At first I received the same errors and non-performance that you did on my
3B1 systems.  Then I tried some experiments and got it to work fine!

The trick is in both the shell script and in the crontab entry.

Running it as my normal login, thad, it all worked fine.

Running it as another user, even su'd to thad, my "doit" script didn't work,
so I added the "echo" of $HOME and $PWD and that provided the clue to set
HOME in the shell script itself since that's what ftp apparently needs, and the
use of "/bin/sh" is important in the crontab entry to prevent a "Nonstandard
shell" error message.

Kevin's posting of his problem highlighted a potentially neato application
I needed to do, so I had more than a passing interest to get this to work.
Thanks for the idea, and accept this fix as my way of saying "Thanks!".

To avoid cluttering the net with example of some stupid errors (:-) I'll just
show the final script, crontab entry, and log of a successful run.

First:
	total 14
	-rw-r--r--  1 thad    users       865 Jan 10 07:22 #ftp-with-cron
	-rw-r--r--  1 thad    users       785 Jan 10 07:17 crontab
	-rw-r--r--  1 thad    users       916 Jan 10 07:16 crontab~
	-rw-r--r--  1 thad    users        61 Jan  9 04:53 doit
	-rwxr-xr-x  1 thad    users       220 Jan 10 07:11 doit2
	-rwxr-xr-x  1 thad    users       218 Jan 10 06:57 doit2~
	-rw-r--r--  1 thad    users      1648 Jan  9 03:19 ftp-with-cron
	-rw-r--r--  1 thad    users        91 Jan  9 04:23 toget

Crontab entry (the first produces no log, the second does):

	#13    7  *  *  *  /bin/sh         -c "/u/thad/test/doit2  >/dev/null"
	15    7  *  *  *  /bin/sh         -c "/u/thad/test/doit2"

The shell script (doit2):

	uname -a
	#who am i			# had to patch out for use with cron
	echo $HOME "   " $PWD
	#
	HOME=/u/thad;export HOME
	#who am i			# had to patch out for use with cron
	echo $HOME "   " $PWD
	#
	cd /u/thad/test
	echo $HOME "   " $PWD
	#
	ftp <<!
	open tlabs3
	binary
	verbose
	get xfr/hdhelp.tar hdhelp.tar
	bye
	!
	exit 0

The results from the cronlog, and note that whomever is actually running cron
does NOT have a $HOME or $PWD:

Thu Jan 10 07:12:00 1991
crontab read
/bin/sh         -c "/u/thad/test/doit2 > /dev/null"

Thu Jan 10 07:14:00 1991
crontab read
/bin/sh         -c "/u/thad/test/doit2"
UNIX thadlabs SYSTEM5 3.51a mc68k
   
/u/thad    
/u/thad    
Verbose mode on.
200 PORT command okay.
150 Opening data connection for xfr/hdhelp.tar (128.15.22.2,1206) (15360 bytes)
.
226 Transfer complete.
15360 bytes received in 0.28 seconds (53 Kbytes/s)
221 Goodbye.
/bin/su uucpadm -c "/usr/lib/uucp/uudemon.poll    >/dev/null"

Thu Jan 10 07:18:00 1991
crontab read
/bin/su uucpadm -c "/usr/lib/uucp/uudemon.hour    >/dev/null"



More information about the Comp.unix.questions mailing list