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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl script will run as root, not as a cron 1

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
0
0
US
I am on HPUX11.i and I have a perl script I wrote that ftp's too a few servers and fetches a few log files. The script runs fine from the command line, and sems to run just the same way from cron based on the command output, however the files are not FTP'd. I am running the cron command as root. I tried wrapping the script in a shell script that sets all the ENV variables and it did not help. There is a firewall between the server the script is running on and the servers I am FTPing to. No errors seem to be occuring, just the FTP is not getting done.

Anyone have any ideas?
 
hi...

a couple of things to look at...

first: do you have the -v (verbose mode) set on the ftp session and are you capturing stdout & stderr to a log file?

second: does your script have a cd to a certain directory? maybe your ftp session is looking at $HOME for the files to send and the log files that it retreived are there?

I think the output of my first question might answer your problem. But when all else fails, have the first line of the script do "env > /tmp/$$.env.log" run it from the command line, then run it again through cron... diff the output. ftp has some behaviors that are different when it knows that it's not running on a terminal.

good luck to you...

...Steve...
 
Steve,

Thanks for the reply. I DID have verbose mode turned on and I am capturing STERR and STOUT via 2<&1 in my cron command. I removed the verbose mode callout, but it is still not working. I tried running the:

env > /tmp/$$.env.log

in my shell script I created to execute my perl script. Still not working. WHat do you mean bu "diff" the output (I am primarily an application guy).

Thanks again,

Nick
 
diff is a simple comparison utility... basically what I meant was to look for anything different between the two environments. the variable $$ is the process id. So in /tmp, you should see 45273.env.log and 534562.env.log (for instance) perhaps post them here?

ls -l *env.log will show you all of your log files

If there is nothing proprietary in those verbose ftp logs, why not post them... let's see what your seeing... might help

I'm assuming that my over-simple answer of checking the $HOME directory had no bearing... If you explicitly cd to a directory in your script, my point was moot..


...Steve...
 
Steve,

Thanks again for the reply. I thought that is what you meant by diff. I was not sure what the $$ did but that is nice to know. I do see a difference between command line and cron ENV settings.

My script does not cd to a direcotry. That admin set the server up so anyone comming in via ftp on my port, goes directly to the right directory.

Below is the "diff" file:

Code:
7,8c7
< PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/contrib/bin:
/opt/mx/bin:/opt/hparray/bin:/opt/nettladm/bin:
/opt/upgrade/bin:/opt/fcms/bin:/opt/pd/bin:/opt/resmon/bin:
/usr/bin/X11:/usr/contrib/bin/X11:/opt/graphics/common/bin:
/opt/scr/bin:/opt/Netscape:/opt/netscape:
/var/opt/netscape/servers/shared/bin:
/var/opt/netscape/servers/bin/slapd/server:
/var/opt/netscape/servers/bin://opt/perl/bin:
/usr/sbin/diag/contrib:/opt/omni/bin:/opt/OV/bin/OpC:
/opt/OV/bin:/opt/ignite/bin:/opt/sec_mgmt/bastille/bin:
/opt/prm/bin:/opt/perf/bin:/opt/sec_mgmt/spc/bin:
/opt/gnome/bin:/opt/sudo/bin:/opt/sudo/sbin:/opt/cfg2html:
/opt/sanscan:/usr/sbin:/opt/OV/bin:/opt/OV/bin/OpC:
/opt/OV/bin/OpC/install:/opt/OV/bin/OpC/utils:.
:/sbin:/home/root:.
< OV_BITMAPS=/etc/opt/OV/share/bitmaps
---
> PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/contrib/bin:
/opt/mx/bin:/opt/hparray/bin:/opt/nettladm/bin:
/opt/upgrade/bin:/opt/fcms/bin:/opt/pd/bin:/opt/resmon/bin:
/usr/bin/X11:/usr/contrib/bin/X11:/opt/graphics/common/bin:
/opt/scr/bin:/opt/netscape:
/var/opt/netscape/servers/shared/bin:
/var/opt/netscape/servers/bin/slapd/server:
/var/opt/netscape/servers/bin://opt/perl/bin:
/usr/sbin/diag/contrib:/opt/omni/bin:/opt/OV/bin/OpC:
/opt/OV/bin:/opt/ignite/bin:/opt/sec_mgmt/bastille/bin:
/opt/prm/bin:/opt/perf/bin:/opt/sec_mgmt/spc/bin:/usr/sbin:
/opt/OV/bin:/opt/OV/bin/OpC:/opt/OV/bin/OpC/install:/sbin:
/home/root:.
9a9
> OV_BITMAPS=/etc/opt/OV/share/bitmaps
12,13d11
< COLUMNS=96
< ORACLE_BASE=/a01/app/oracle
14a13
> ORACLE_BASE=/a01/app/oracle
25d23
< ERASE=^H
26a25
> ERASE=^H
34c33
< DISPLAY=155.49.15.40:0.0
---
> DISPLAY=
38d36
< NETFMT=/usr/sbin/netfmt
39a38
> NETFMT=/usr/sbin/netfmt
46d44
< TERM=hp
48c46
< PWD=/home/opc_op
---
> PWD=/
51d48
< OV_CONF=/etc/opt/OV/share/conf
52a50
> OV_CONF=/etc/opt/OV/share/conf
56d53
< NETFMT_LOG_FILE=/var/adm/nettl.LOG00
57a55
> NETFMT_LOG_FILE=/var/adm/nettl.LOG00
60d57
< LINES=24

And below is the cron FTP output:

Code:
Net::FTP: Net::FTP(2.65)
Net::FTP:   Exporter(5.562)
Net::FTP:   Net::Cmd(2.21)
Net::FTP:   IO::Socket::INET(1.25)
Net::FTP:     IO::Socket(1.26)
Net::FTP:       IO::Handle(1.21)

Net::FTP=GLOB(0x4010be54)<<< 220 N2WEB015 Microsoft FTP Service (Version 5.0).
Net::FTP=GLOB(0x4010be54)>>> user ovmon

Net::FTP=GLOB(0x4010be54)<<< 331 Password required for ovmon.
Net::FTP=GLOB(0x4010be54)>>> PASS ....
Net::FTP=GLOB(0x4010be54)<<< 230-This is a private FTP site for authorized users only.  All others must disconnect now.
Net::FTP=GLOB(0x4010be54)<<< 230 User ovmon logged in.
Net::FTP=GLOB(0x4010be54)>>> TYPE I

Net::FTP=GLOB(0x4010be54)<<< 200 Type set to I.
Net::FTP=GLOB(0x4010be54)>>> PASV

Net::FTP=GLOB(0x4010be54)<<< 227 Entering Passive Mode (192,168,98,11,6,188).
Net::FTP=GLOB(0x4010be54)>>> RETR monout_n2web015.txt

Net::FTP=GLOB(0x4010be54)<<< 125 Data connection already open; Transfer starting.
Net::FTP=GLOB(0x4010be54)<<< 226 Transfer complete.
Cannot open monout_n2web015.txt:  at /home/opc_op/ftpdmz.pl line 67.

 
Steve,

With your help I figured it out via the PWD in the diff command. I was executing the script from the /home/opc_op directory and cron from /.

Rookie mistake. I modified my script accordingly.

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top