Solved

Perl system (mailx) is not sending the complete file

Posted on 2008-10-08
9
578 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now