Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: perl script in nohup running from crontab

by graff (Chancellor)
on Sep 23, 2011 at 02:53 UTC ( [id://927488]=note: print w/replies, xml ) Need Help??


in reply to perl script in nohup running from crontab

A couple things that might be worth trying...
# crontab -l * * * * * perl /root/nfs_share/SCRIPTS/cron_ncp.pl >>/tmp/cron_ncp.tmp +.txt 2>&1
That is, redirect output somewhere else, just to be sure there aren't permission issues, and include stderr together with stdout.
#!/usr/bin/perl use strict; use warnings; my $tmp = `ps -ef`; if ( $tmp !~ /ncp_run.tcl/ ) { my $cmd = 'expect -f /root/nfs_share/SCRIPTS/ncp_run.tcl'; print "starting now: $cmd\n"; exec $cmd; } printf "ncp_run.tcl is already running as of %s: %s\n", scalar(localti +me), $tmp );
That is, output a little more information about what's happening, and use exec instead of system (and do a bit of tidying/tightening up).

Replies are listed 'Best First'.
Re^2: perl script in nohup running from crontab
by tanuj (Novice) on Sep 23, 2011 at 09:26 UTC
    Thanks graff,

    cron is executing the script, but now i have a different problem.

    I have all the scripts under /root/nfs_share/SCRIPTS folder as you can see i was trying to run a script ncp_run.tcl (which is again under SCRIPTS dir). In this ncp_run.tcl file i am socurcing some other files

    source resource.conf source init.tcl

    so while corn is executing the script it is throwing error
    couldn't read file "resource.conf": no such file or directory while executing "source "resource.conf"" (file "/root/nfs_share/SCRIPTS/ncp_run.tcl" line 1)
    so is it something like corn is running this in some other environment. here is some of the datails:

    [root@perflnx14 SCRIPTS]# which crontab /usr/bin/crontab [root@perflnx14 SCRIPTS]# echo $SHELL /bin/bash [root@perflnx14 SCRIPTS]# echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/s +bin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/nfs_share/SCRIPTS:/root/n +fs_share/SCRIPTS/ [root@perflnx14 SCRIPTS]# echo $HOME /root

    but if i run this script manually  expect -f ncp_run.tcl</it will work finep> once again thanks for helping me out in this ;-)

      When you log in, your profile is loaded, paths are defined, etc. That does not happen with cron.

      So, when cron'ing, explicitly define the full path for every file you open.

      As indicated by hbm above, the next thing to try is to edit the contents of "nap_run.tcl":
      source /root/nfs_share/SCRIPTS/resource.conf source /root/nfs_share/SCRIPTS/init.tcl
      It's curious that your "nap_run.tcl" file is actually being used/interpreted as a (ba)sh shell script, despite the fact that the ".tcl" extension would lead a casual observer to think that it's actually a tcl script instead. Is it your intention to use the ".tcl" extension on shell scripts? And if "resource.conf" and "init.tcl" don't start with shebang lines, is it your intention that they are also used/interpreted as shell scripts?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://927488]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found