Find the answer to your Linux question:
Results 1 to 2 of 2
Hello. I have wrote a simple perl script (see below) that executes a RAID status command on a remote machine over and emails the output of the command to me. ...
  1. #1
    Just Joined!
    Join Date
    Feb 2011
    Posts
    1

    Perl script not running from cron

    Hello. I have wrote a simple perl script (see below) that executes a RAID status command on a remote machine over and emails the output of the command to me. I can run the script locally and see the command output in my email body, but if I create a cron job the email message body is blank. I assume it's something like cron not having permissions to execute the command within the script. I have the script set to -rwxr-xr-x (755) and owner is root so cron should be able to run everything. Please advise guys. Thanks!

    Code:
    #!/usr/bin/perl
    
    my $cmd = `ssh -l root 10.0.0.1 tw_cli /c4 show`;
    
      use Mail::Sendmail;
    
      %mail = ( To      => 'me',
                From    => 'raidstatus',
                Subject => "Raid Status",
                Message => "$cmd"
               );
    
      sendmail(%mail) or die $Mail::Sendmail::error;

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    When a script runs fine locally but not in cron it indicates a difference in environments. Remember that cron does NOT run you login profile script(s) before running the script. Often PATH is the problem. When writing a script that is to be run in cron specify the full path for the commands.

    Instead of:

    ssh

    it should be:

    /path/to/ssh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...