Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


sending_email

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sending_email [2020/04/20 17:43] juckinssending_email [2020/11/12 10:30] (current) juckins
Line 4: Line 4:
 #!/usr/bin/perl -w #!/usr/bin/perl -w
  
-$sysadmin = "juckins\@gmail.com";+$sysadmin = "user\@domain.com";
 $script_name = "test"; $script_name = "test";
-$archive_data_dir = "/var/www/html/amtrak_status/tat_archive_sunny_carto_raw/data_archive"; +$archive_data_dir = "/a/b/c"; 
 $latest_file_download = `ls -1 $archive_data_dir| tail -n 1`; $latest_file_download = `ls -1 $archive_data_dir| tail -n 1`;
  
Line 15: Line 15:
   $now = `date`;   $now = `date`;
   chomp($now);   chomp($now);
 +}
 +</code>
 +
 +<code>
 +my $email_message_file = "email.txt";
 +my $now = &now();
 +open (EMAIL, ">$email_message_file") or die "Cannot open file for writing: $!";
 +print EMAIL "$now\n\n";
 +print EMAIL "$this_filename.pl reported an error.  Please investigate.\n";
 +close (EMAIL);
 +send_reminder("user\@domain.com", "$this_filename.pl reported an error", "$email_message_file");
 +
 +#---
 +# send reminder if error encountered
 +# email recipient, email subject, and filename for email body will be passed in
 +#---
 +sub send_reminder {
 +  my ($recipient, $subject, $body) = @_;
 +  print LOG "  $PID sending email to: $recipient about: $subject\n";
 +  my $reminder_results = "";
 +  $reminder_results = system("send_reminder.csh \"$recipient\" \"$body\" \"$subject\"");
 +  print LOG "  $PID reminder_results:\n$reminder_results\n";
 } }
 </code> </code>
sending_email.1587418989.txt.gz · Last modified: 2020/04/20 17:43 by juckins