http://qs1969.pair.com?node_id=927346


in reply to perl script in nohup running from crontab

Can you run the script outside of cron? all by itself from the commandline? Without using Perl?
  • Comment on Re: perl script in nohup running from crontab

Replies are listed 'Best First'.
Re^2: perl script in nohup running from crontab
by raybies (Chaplain) on Sep 22, 2011 at 12:27 UTC

    ALSO, cron has minimal path provided by a minimal shell, so if it runs on your default shell, it may still not run in cron...

    if the user installed expect or nohup in a dir that's not accessible in cron's shell, you may need to hardpath (provide the full path to every executable run in a script run in cron) them, for them to work within cron.

      i added the full path as /use/bin/expect but still no luck.
        Have you specified the full path of nohup, too?
        You may also want to look at re-setting environment variable for PATH within the script so that the system knows how to find all the executables (/usr/bin, etc.) instead of hardcoding them all in to the command.
Re^2: perl script in nohup running from crontab
by tanuj (Novice) on Sep 22, 2011 at 13:37 UTC
    yes I am able to run this script out side the cron. even if the modify the same script $cmd=date and run the same script it will work in corn. so i have some doubt in $cmd='nohup expect -f /root/nfs_share/SCRIPTS/ncp_run.tcl &';

      Any errors in /var/cron/log or wherever you system keeps them? If you can't view that log, add 2>&1 (or whatever is appropriate on your system) to redirect STDERR to your own log file.

      Your cron entry starts with "perl". Why, when you have #!/usr/bin/perl in your script?

      I'd also add #!/path/to/expect -f to the .tcl, to simplify your $cmd.

      And excessive pipe alert in your grep...

      [root@perflnx14 SCRIPTS]# crontab -l * * * * * /root/nfs_share/SCRIPTS/cron_ncp.pl >>/root/nfs_share/SCRIPT +S/temp.txt ---------------- cron_tab.pl script: #!/usr/bin/perl use warnings; use strict; #my $cmd='nohup expect -f /root/nfs_share/SCRIPTS/ncp_run.tcl &'; my $cmd='nohup /root/nfs_share/SCRIPTS/ncp_run.tcl &'; #my $tmp= `ps -ef | grep -v grep | grep ncp_run.tcl | wc -l`; my $tmp= `ps -ef | grep -c [n]cp_run.tcl`; if($tmp == 1) { print"already running\n"; } else { print"not running\n"; system $cmd; }
        ya i tried with putting the patj /usr/bin/expect ..but no luck in logs everything looks fine to me:
        [root@perflnx14 SCRIPTS]# tail /var/log/cron Sep 21 23:15:01 perflnx14 crond[1932]: (root) CMD (perl /root/nfs_shar +e/SCRIPTS/cron_ncp.pl >>/root/nfs_share/SCRIPTS/temp.txt) Sep 21 23:16:01 perflnx14 crond[1947]: (root) CMD (perl /root/nfs_shar +e/SCRIPTS/cron_ncp.pl >>/root/nfs_share/SCRIPTS/temp.txt) Sep 21 23:17:01 perflnx14 crond[1972]: (root) CMD (perl /root/nfs_shar +e/SCRIPTS/cron_ncp.pl >>/root/nfs_share/SCRIPTS/temp.txt)