Tag Archives: bash

Ping Multiple Host

#!/bin/bash

HOSTS=(192.168.3.241 192.168.3.240 192.168.3.21 192.168.3.216 192.168.3.100 192.168.3.213 192.168.2.239 192.168.2.229 192.168.2.230 192.168.2.218 192.168.2.241 192.168.2.206 192.168.3.219)

count=${#HOSTS[@]}
index=0
while [ "$index" -lt "$count" ]; do
 echo -e "-----------------------------------\n"
 echo -e "Haciendo ping ${HOSTS[$index]} ... \n"
 ping -c 3 ${HOSTS[$index]}
 let "index++"
done

Send email Perl with attached files and remove file after sent

send_email_file_report.pl

#!/usr/bin/perl

use MIME::Lite;

my $attached_file = $ARGV[0];
my $report_directory = "/mnt/reports";

my $msg = MIME::Lite->new(
 From => 'xxxx@xxxx.com',
 To => 'xxx@xxx.com',
 Cc => 'xxxx@xxxx.com, xxxxx@xxxx.com',
 Bcc => 'xxx@xxx.com, xxx@xxx.com',
 Subject => "$attached_file",
 Type => 'multipart/mixed',
);

$msg->attach(
 Type => 'TEXT',
 Data => "Mensaje : $attached_file \nNota: Este correo ha sido generado autom√°ticamente por favor no responda a este mensaje.",
);

$msg->attach(
 Type => 'text/plain',
 Path => "$report_directory/$attached_file",
 Filename => "$attached_file",
 Disposition => 'attachment'
);

$msg->send or die "Mensaje no enviado";

system("rm -rf $report_directory/$attached_file");


------------ bash execution ------------------------

#!/bin/bash

report_directory="/mnt/reports"
exec_directory="/root/bin"

cd $report_directory
for i in *.csv; do $exec_directory/send_email_file_report.pl $i; done