前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >perl dancer 基础8

perl dancer 基础8

作者头像
franket
发布2022-03-25 17:26:31
8480
发布2022-03-25 17:26:31
举报
文章被收录于专栏:技术杂记

添加展示层[V]

在dancer中 TEST-APP/views/ 是控制显示的,创建 TEST-APP/views/check_class/check_database_backup.tt

代码语言:javascript
复制
[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("yes\n");exp_continue;}],
	    [ qr/password:/i,sub { my $self = shift;$self->send("$pass\n");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: 一般而言,密码不要直接写到功能逻辑里面,不灵活,不安全

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 添加展示层[V]
  • 添加功能逻辑[M]
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档