我对PERL脚本没有太多了解。下面是一个Perl脚本,它试图通过SSO身份验证登录到网站,然后注销。但是,我对脚本所做的其他事情并不了解。我注意到该脚本现在给出的输出与预期不同。需要帮助以了解获得与预期不同的输出的原因是什么。
脚本代码:
#!/opt/SP/perl/perl-5.18.2-reloc/bin/perl -w
use strict;
use warnings;
use LWP;
use Time::Piece;
use Time::HiRes qw[gettimeofday tv_interval];
my $time1=[gettimeofday()];
my $browser = LWP::UserAgent->new;
$browser->agent($0.' $Revision: 778 $');
$browser->cookie_jar( {} );
my @ns_headers = (
'Accept' => 'text/html, text/plain, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*',
'Accept-Charset' => 'iso-8859-1,*',
'Accept-Language' => 'en-US',
);
my $login= "https://mywebsite.com/opensso/rest/1.0/opensso/identity/authenticate";
my $logout="https://mywebsite.com/opensso/rest/1.0/opensso/identity/logout";
my $response;
# Logon
$response = $browser->post(
$login,
[
username => 'test@123',
password => 'pssd123',
],
@ns_headers);
do_die("login: ".$response->status_line) unless $response->is_success;
do_die("No token received ".$response->content) unless $response->content=~ /^token\.id=(\S+)$/;
# Logoff
my $token= $1;
$response = $browser->post(
$logout,
[
subjectid => $token,
],
@ns_headers);
do_die("logout: ".$response->status_line) unless $response->is_success;
my $date = localtime->strftime('%y%m%d');
my $time = localtime->strftime('%R');
my $milliseconds = tv_interval($time1);
open (MYFILE, '>>/var/SP/data/reporting/customersystems/result_KPI.txt');
print MYFILE "$date $time GIS sso_logon_logoff 0 $milliseconds\n";
close (MYFILE);
exit 0;
sub do_die {
my($text)= @_;
# $text=~ s/\n/\\n/g;
print $text;
open (MYFILE, '>>/var/SP/data/reporting/customersystems/result_KPI.txt');
print MYFILE "$date $time GIS sso_logon_logoff 1 $milliseconds\n";
close (MYFILE);
exit 1;
}
从下面的输出中可以看到,突然我们看到了 脚本输出中不会出现“ GIS sso_logon_logoff 1”。 有人可以告诉我获取此输出的原因是什么。 预先感谢。
输出:
181212 09:11 GIS sso_logon_logoff 0 0.466719
181212 09:12 GIS sso_logon_logoff 0 0.483316
181212 09:13 GIS sso_logon_logoff 0 0.482076
181212 09:14 GIS sso_logon_logoff 0 0.515636
181212 09:15 GIS sso_logon_logoff 0 0.490774
181212 09:16 GIS sso_logon_logoff 0 0.449388
GIS sso_logon_logoff 1
181212 09:18 GIS sso_logon_logoff 0 0.543591
181212 09:19 GIS sso_logon_logoff 0 0.446938
181212 09:20 GIS sso_logon_logoff 0 0.683515
GIS sso_logon_logoff 1
181212 09:22 GIS sso_logon_logoff 0 0.453028
GIS sso_logon_logoff 1
GIS sso_logon_logoff 1
GIS sso_logon_logoff 1
GIS sso_logon_logoff 1
GIS sso_logon_logoff 1