Solved

Perl system (mailx) is not sending the complete file

Posted on 2008-10-08
9
580 Views
Last Modified: 2013-12-27
I have done this a half dozen time successfully.  I have a perl file on a Solaris OS system.  At the end of the program I want it to send the last file created.  
The command I am using is
system ("mailx -r OurGroup\@domain.net -s \"Email Subject\" My.Name\@domain.net </home/myname/criticals/logs/thefile.data");

Instead of getting the entire file, I am getting the first column (before the tab) of each line (except the first line).
The file reads&
Node                            NodeAlias                       AlertGroup                   Summary                         Tally       Acknowledged        

CFTC - 2nd Floor UPS            172.21.131.225                                               lgpEventConditionEntryAdded: This notification is sent each time a condition is inserted into the conditions table.    909            1        
       

CFTC - 2nd Floor UPS            172.21.131.225                                                lgpEventLowBatteryWarning: The battery's remaining charge is less than  or equal to the agent's configured low threshold 'lgpPwrConfigLowBatteryWarningTime'.                  255            1                

CFTC - 2nd Floor UPS            172.21.131.225                                                lgpEventConditionEntryRemoved: This notification is sent each time a co ndition is removed from the conditions table.   909            1        
       

CFTC - 2nd Floor UPS            172.21.131.225                                                lgpEventBatteryTestFailed: The device has reported a battery self-test  failure.                        190            1                

CFTC - 2nd Floor UPS            172.21.131.225                                                lgpEventLoadTransferedToBypass: The device has transfered the load to t he bypass source.               192      
 

Instead I am getting
Node                                NodeAlias                           AlertGroup                          Summary                             Tally       Acknowledged            

CFTC - 2nd Floor UPS

CFTC - 2nd Floor UPS

CFTC - 2nd Floor UPS

CFTC - 2nd Floor UPS

CFTC - 2nd Floor UPS
 
Like I said, I have done this many times and this is the first time I have had this problem.
 
0
Comment
Question by:cmaries
  • 3
  • 3
  • 2
9 Comments
 
LVL 6

Expert Comment

by:wwnosal
ID: 22672192
have you tried to that a bit differently:

system ("cat your_file | mailx  -r OurGroup\@domain.net -s \"Email Subject\" My.Name\@domain.net ");

is this shows the same behaviour?


0
 
LVL 28

Expert Comment

by:FishMonger
ID: 22676392
Why not use the MIME::Lite module to send the email?

http://search.cpan.org/~rjbs/MIME-Lite-3.021/lib/MIME/Lite.pm
0
 

Author Comment

by:cmaries
ID: 22680429
Thank you both for your comments.
wwnosal -- I tried your suggestion and I got the same results.  From a command prompt when I type cat your_file,  I get the entire file but when I run the command in the .pl I only get "the first segment of each line.

FishMonger -- I don't want to circumvent this issue, by using a different tool.  Maybe I will consider this as a last resort.

Thanks again.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:cmaries
ID: 22680518
If it helps...this is how each line is created in the file

for (my $x=1; $x<$size_report-5; $x=$x+1){
     $report[$x] =~s/^\s+//;
     $report[$x] =~s/\s+$//;
     $temp = $report[$x];
     $temp = sprintf("%-30s",$report[$x]);
     $newline = $newline . $temp;
     if(substr($report[$x],0,2) =~ /^\-+/) {$newline = "";}
     if(substr($report[$x],0,5) =~ /^Tally/ || $report[$x] =~ /^\d+\s+\d+/) {
          print "nline $newline\n\n\n";
          print FILE1 "$newline\n\n";
          $newline = "";
     }
}


0
 
LVL 6

Expert Comment

by:wwnosal
ID: 22680966
Can you attach an example of the file that is causing the problems?

0
 

Author Comment

by:cmaries
ID: 22686097
I did...scroll up.  Look for "The file reads" and "Instead I am getting".  This is the file I am trying to send with the command
system ("mailx -r OurGroup\@domain.net -s \"Email Subject\" My.Name\@domain.net </home/myname/criticals/logs/thefile.data");

I also included the section of the perl file that reads the raw data file and creates this file...
 for (my $x=1; $x<$size_report-5; $x=$x+1){
    $report[$x] =~s/^\s+//;
    $report[$x] =~s/\s+$//;
    $temp = $report[$x];
    $temp = sprintf("%-30s",$report[$x]);
    $newline = $newline . $temp;
    if(substr($report[$x],0,2) =~ /^\-+/) {$newline = "";}
    if(substr($report[$x],0,5) =~ /^Tally/ || $report[$x] =~ /^\d+\s+\d+/) {
         print "nline $newline\n\n\n";
         print FILE1 "$newline\n\n";
         $newline = "";
    }
}

0
 
LVL 6

Expert Comment

by:wwnosal
ID: 22686522
yeah but exactly the output of this script is what I want to see..
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 500 total points
ID: 22687086
Rather than doing a copy/paste of file and posting it in the html, use the "Attach File" option, which is just below the Comment box, and attach the file as a link so that we can see its exact contents.

See if building the system call like this makes any difference.

my @email_args = (
                               'mailx',
                               '-r OurGroup@domain.net',
                               '-s "Email Subject"',
                               'My.Name@domain.net',
                               '< /home/myname/criticals/logs/thefile.data',
                              );

system(@email_args);
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question