script runs fine until I call it from cron

I have a script that runs every 15 minutes to download files when they become available. It works great from cron. Well it did until I added this:

set myIP to getInternalIP()
if myIP is " unknown " then
	return
        -- for testing
	--display dialog "you are not connected"
end if

-- my script

to getInternalIP()
	set the_interface to 0
	repeat
		set ip_internal to ""
		try
			set ip_internal to do shell script ("ipconfig getifaddr en" & the_interface)
		end try
		if ip_internal is not "" then exit repeat
		set the_interface to the_interface + 1
		if the_interface = 5 then
			set ip_internal to " unknown "
			exit repeat
		end if
	end repeat
	return ip_internal
end getInternalIP

Now when I run it out of cron it doesn’t see it’s connection and returns ( or tells me I am not connected if the display dialog is uncommented. )

I call it from cron like this

I can run this manually by clicking on it and from the command line without this problem. Anyone know what the problem might be? I don’t need to know my ip I just need to know if I have a network connection so I don’t call something that will hang if it doesn’t have network.

Thanks for any help.

Peace,
Lois

Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)

I suspect the problem may be this line:

set ip_internal to do shell script (“ipconfig getifaddr en” & the_interface)

cron has a different environment and typically has a different $PATH setup. Try using the full path to the ipconfig command. On my machine that would be:

set ip_internal to do shell script (“/usr/sbin/ipconfig getifaddr en” & the_interface)

Andy

Browser: Safari 412
Operating System: Mac OS X (10.4)

Hi Lois,

here is an easier way to check internet connection

if (chkUP("http://www.apple.com") or chkUP("http://www.google.com")) is false then return

-- my script

to chkUP(theURL)
	return (count (get ((theURL as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0
end chkUP