Perl Script issue. What am I doing wrong?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Script issue. What am I doing wrong?
# 8  
Old 03-18-2009
Quote:
Originally Posted by KevinADC
Pludis code has a small typo, it has $red where it should be $rec.
Whoops. But a perfect demonstration for how useful perl -c and use strict; are Smilie

Quote:
Originally Posted by SkySmart
[...]
sorry for not including the codes.
[...]
would you happen to know how to include a code in ur code that will email the file to a set of email addresses?
[...]
Not a problem, everyone started as a new guy here at some point.

To send the results as an eMail, you've got a few options, but none can be done using simple Perl commands.
  1. The (probably) easiest way would be to use a module like Mail::Send
  2. If you want to have a lot of control about how the mail is sent, use Net::SMTP
  3. If you don't want to/can't install modules, open a file handle to a pipe that feeds into the sendmail program. Example here
# 9  
Old 03-18-2009
Quote:
Whoops. But a perfect demonstration for how useful perl -c and use strict; are
hehehe..... very true Smilie
# 10  
Old 03-18-2009
Quote:
Originally Posted by SkySmart
yes i did read your post in the other thread. when i went to use it i wasn't getting any response back. i think the problem was in the line that i bolded.

i'll try this script of yours and see if it outputs something. thanks a million.
It does assume that the pattern to find is exactly STATE: OK, if the pattern is different you need to change accordingly.
# 11  
Old 03-18-2009
Quote:
Originally Posted by SkySmart
below is the code I came up with to get the file data.txt as an attachment and send it out:

Code:
sub test_mail {
my $msg = MIME::Lite->new(
   From    =>  'noreply@faroko.com',
   To      =>  'jamie.henson@faroko.com',
   Subject =>  'TESTING',
   Type    =>  'multipart/mixed',
);

$msg->attach(
    Type   =>  'TEST',
    Data   =>  "TESTING ATTACHMENT FEATURE",
);

$msg->attach(
    Type   =>   'TEST',
    Path   =>   'data.txt',
    Filename => 'data.txt',
);

$msg->send;
}


How can I incorporate this script into the existing script to have it send out the data.txt file to the email addresses.
First thing is you have to check if MIME::Lite is installed. It does not come installed by default. If it is or you can install it just laod the module:

use MIME::Lite;

and call the subroutine as needed:

test_mail();

the path to the attachment will probably need to be changed since it assume the attached document is in the same folder as the perl script. Easiest to use the full path if you know if:

Path => '/full/path/to/data.txt'
# 12  
Old 03-18-2009
Quote:
Originally Posted by pludi
Whoops. But a perfect demonstration for how useful perl -c and use strict; are Smilie


Not a problem, everyone started as a new guy here at some point.

To send the results as an eMail, you've got a few options, but none can be done using simple Perl commands.
  1. The (probably) easiest way would be to use a module like Mail::Send
  2. If you want to have a lot of control about how the mail is sent, use Net::SMTP
  3. If you don't want to/can't install modules, open a file handle to a pipe that feeds into the sendmail program. Example here

i included a code on the first page of this thread. do you see anything wrong with it? i'm running the script but its not sending out emails.
# 13  
Old 03-18-2009
see my post above
# 14  
Old 03-19-2009
Can someone please tell me why the value stored in the $date_string variable below isn't showing?

in the email that is sent out i get the word "$date_string" instead of the contents of the variable.


Code:
test_mail ();

sub test_mail {
my $msg = MIME::Lite->new(
   From    =>  'noreply@faroko.com',
   To      =>  'jamie.henson@faroko.com',
   Subject =>  'Status - \'$date_string\'',
   Type    =>  'multipart/mixed'


thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing perl script in Linux gives :Exec format error. Wrong Architecture

i have perl script that used to be working great , once i edit it in windows and convert it to UTF-8 and then via FTP return it . also did: chmod +x foo.pl and then when i try to run it : ./foo.pl im getting this error: ./foo.pl: Exec format error. Wrong Architecture.... (4 Replies)
Discussion started by: umen
4 Replies

2. Shell Programming and Scripting

What is wrong with my perl script?

i managed to write a perl script for nagios. now, the script works. but i think there's somethign wrong with the exit codes. because the script doesn't show the output of the results in nagios, it instead shows null. please tell me what i'm doing wrong here: #!/usr/local/bin/perl use... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Issue regarding dos2unix perl script

Hi All, I have pearl script which will check and convert the file: INFO("dos2unix_cmds".$#{$dos2unix_cmds}); if ( $#{$dos2unix_cmds} == 0 ) { my $convert_cmd = $$dos2unix_cmds; my $rename_cmd = $$dos2unix_cmds; --conversion going here else INFO ("No need to... (8 Replies)
Discussion started by: saps19
8 Replies

4. Shell Programming and Scripting

Perl script issue

Hi All, I have a perl script which I am using in Windows environment. There is one more file called "functions.txt" which is having all the functions defined to used in my perl script. And the path for this function file is defined in my perl script. Howeever sometimes I am getting below error... (4 Replies)
Discussion started by: gr8_usk
4 Replies

5. Shell Programming and Scripting

Simple issue, what is wrong?

I had this working a few days ago but I since changed it. Heres the code x=1 while 1 2 3 4 5 6 1=$(ps -ef | grep process | awk '{ print $2}') if then echo "The database is accepting connections..." echo "Now I will check the next process" 2=$(ps -ef | grep process1 |... (10 Replies)
Discussion started by: jeffs42885
10 Replies

6. Shell Programming and Scripting

Perl...getting wrong output?

Good morning! Im trying to write and learn at the same time a simple script. fTHe script should tell me if a number is odd or even/ #!/usr/bin/perl $num = 10; $string1 = "This number is odd"; $string2 = "This number is even"; if ($num /= 2) { print "$string1\n"; }else{ ... (3 Replies)
Discussion started by: bigben1220
3 Replies

7. Web Development

Accessing a Perl CGI script, security issue

Hi Everybody, I was wondering if it was possible for someone to gain access to my Perl CGI scripts before they are interpreted by Perl (mod_perl on apache2) i.e. getting a hold of my raw scripts and not the html output? Let's say I use the DBI module where I have the hostname, user and... (2 Replies)
Discussion started by: z1dane
2 Replies

8. Shell Programming and Scripting

wrong output in perl script

Hi, Here is my piece of code-- #!/usr/bin/perl my $Time_Stamp ; my $User_Name; my $Success; my $Failure; my $ErrorCode; my $ErrorMsg; my $logDir = $ARGV; my $logPrefix = $ARGV; die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix; die "Log dir $logDir doesn't... (2 Replies)
Discussion started by: namishtiwari
2 Replies

9. Shell Programming and Scripting

Perl script issue: print

Can someone tell me what I'm doing wrong with my perl script? I am new to Perl. This isn't even the final script, I'm just testing to see if it will print the directories with the files in it. For some reason my output is only printing the 1st, 6th, and last entries of the @sub_dir array. Each... (3 Replies)
Discussion started by: man
3 Replies

10. Shell Programming and Scripting

Perl Script Issue - Please Help * Thanks!!!

Please help me with my script please. I am trying to do the following: 1. Read files for the current directory 2. Open and read from nbe files files only 3. Read only the lines with the results pattern 4. Split the line and print 3rd field Please indicate what line I need to modify. ... (8 Replies)
Discussion started by: jroberson
8 Replies
Login or Register to Ask a Question