![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Conditional FTP | Dastard | Shell Programming and Scripting | 2 | 06-21-2008 07:38 AM |
| AWK - conditional cause | Rafael.Buria | Shell Programming and Scripting | 2 | 01-28-2008 01:24 PM |
| conditional statement | lalelle | Shell Programming and Scripting | 8 | 08-21-2007 08:57 AM |
| conditional split | braindrain | Shell Programming and Scripting | 5 | 03-11-2006 03:54 AM |
| Conditional Statements | cstovall | Shell Programming and Scripting | 1 | 05-15-2005 05:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Some one please help me: I need to perl code for a conditional block:
I believe I need to put the $email->send; command in a conditional block that checks if $duplicate_ip or $duplicate_host is defined, and then send the email. How can I do that: use strict; use warnings; use MIME::Lite; my (%ip, %host, $duplicate_ip, $duplicate_host, @linevals, $outline); my $host_file = '/etc/hosts'; open my $file, '<', $host_file or die "can't open $host_file $!"; while (<$file>) { chop; if( my ($ip, $host) = /^#?([\d.]+)\s+(\S+)/ ) { @linevals = split; $outline = $linevals[0] . "\t" . $linevals[1] . "\n"; push @{$ip{$ip}}, $outline; push @{$host{$host}}, $outline; } } close $file; #print "Duplicate IP's with hostnames\n"; foreach my $ip ( keys %ip ) { if ( @{$ip{$ip}} > 1 ) { $duplicate_ip .= join ('', @{$ip{$ip}}) . "\n\n"; } } #print "\nDuplicate hostnames with IP's\n"; foreach my $host ( sort keys %host ) { if ( @{$host{$host}} > 1 ) { my ($ip) = $host{$host}[0] =~ /^#?([\d.]+)/; unless ( @{$ip{$ip}} > 1 ) { $duplicate_host .= join('', @{$host{$host}}) . "\n\n"; } } } my $email_msg = <<EMAIL_MSG; The following entries in the host file are duplicates either by IP address or by hostname. Duplicate IP addresses: $duplicate_ip Duplicate Hostnames: $duplicate_host EMAIL_MSG print $email_msg; my $email = MIME::Lite->new( From => 'xxx@xxx.com', To => 'xxxx@xxx.com', #Cc => 'xxx@xx.com,xxxx@att.com', Subject => 'Host file duplicates', Data => $email_msg ); $email->send |
|
||||
|
Is this code goes after $email->send:
if ($duplicate_ip || $duplicate_host) then $email->send bottom line is e-mail will be send if duplicate is found otherwise don't send an email. thanks Last edited by ricky007; 03-06-2008 at 12:18 AM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|