添加展示层[V]
在dancer中 TEST-APP/views/
是控制显示的,创建 TEST-APP/views/check_class/check_database_backup.tt
[dancer@dancer-test ~]$ cat TEST-APP/views/check_class/check_database_backup.tt
<form class="form-cr" method="POST" action="/check_backup">
<h2 class="form-cr-heading">Please input the Email address :</h2>
<% IF errmsg %><p class="alert alert-error"><% errmsg %></p><% END %>
<textarea name="email_addr" cols=40 rows=4>
Type your Email address here...
</textarea>
<button class="btn btn-large btn-primary" type="submit">submit</button>
</form>
[dancer@dancer-test ~]$
添加功能逻辑[M]
代码语言:javascript复制[dancer@dancer-test bin]$ cat D_check_backup_for_db.pl
#!/usr/bin/perl
#require Expect
#require Getopt::Std
#
use Expect;
use Getopt::Std;
use strict;
my (%opts,$host,$user,$pass);
getopts( 'p:h',%opts );
&help_info() if $opts{h};
&help_info() unless $opts{p};
#bakdir info
my $bakdir="/data/backupdir";
my $baklog="$bakdir/backuplog/backup.log";
my $patt="innobackupex.*completed";
my $chkfile="xtrabackup_checkpoints";
my $num=10;
#comment
my $com1="-"x40;
my $com2="----LSN_Status"."-"x26;
my $com3="----Backup_Resault"."-"x22;
#set expect timeout
my $timeout=3;
open PASSFILE,"< $opts{p}" or die "Can't open $opts{p}!";
while(<PASSFILE>){
$_ =~ s/(^s |s $)//;
chomp($_);
($host,$user,$pass)=split (/s /,$_);
}
close PASSFILE;
#autocheck of hostA and hostB
foreach (("hostA","hostB")){
#my $exp = Expect->spawn("ssh $user@$host 'ssh $_ "echo $com1; hostname; echo $com2; cat $bakdir/2015-*/$chkfile ; echo $com3;grep $patt $baklog | tail -n $num " ' ");
my $exp = Expect->spawn("ssh $user@$host 'ssh $_ "
echo $com1;
hostname;
echo $com2;
cat $bakdir/2015-*/$chkfile;
echo $com3;
grep $patt $baklog | tail -n $num; " '
");
$exp->expect($timeout,
[ qr/(yes/no)/i,sub { my $self = shift;$self->send("yesn");exp_continue;}],
[ qr/password:/i,sub { my $self = shift;$self->send("$passn");exp_continue;}],
);
}
sub help_info {
print <<EOF
Usage:
$0 -p <password_file> [-h]
-h optical argument
display this help info
-p specified the path of password file
Example:
command:
$0 -p /path/to/passwordfile
EOF
;
exit 0;
}
[dancer@dancer-test bin]$
Note: 一般而言,密码不要直接写到功能逻辑里面,不灵活,不安全