Created
November 11, 2016 10:51
-
-
Save AmarJazzz/83b24f7f8a6f70a619d768f64dccc76a to your computer and use it in GitHub Desktop.
Perl Log sample script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################### | |
## LOG SCRIPT ## | |
## Written by :- AMAR ## | |
########################### | |
#!/usr/bin/perl | |
use Net::SSH::Expect; | |
use POSIX qw(strftime); | |
$server = "192.168.1.122"; | |
$username = "amar"; | |
$passwd = "Sample\@123"; | |
my $now = strftime('%d-%m-%Y %H:%M:%S',localtime); | |
open ($Log,"+>>","/home/amar/logs/Sample.log"); | |
print $Log ("$now ***********[START OF SCRIPT : DATABASE CHECK]***********\n"); | |
print $Log ("$now Trying to connect to the Server : $server\n"); | |
$ssh = Net::SSH::Expect->new(host => "$server",password => "$passwd",user => "$username",raw_pty => 1, timeout => 2); | |
$login_output=$ssh->login(); | |
if ( $login_output !~ /Last login:/) | |
{ | |
print "Failed to login into the Server : $server\n"; | |
print $Log ("$now Failed to login into the Server : $server, Check the credentials\n"); | |
} | |
else | |
{ | |
print $Log ("$now Logged into the Server : $server\n"); | |
## PERFORM UR ACTIVITY ..... | |
print "Database check was successful\n"; | |
print $Log ("$now DatabasE check was successful\n"); | |
} | |
print $Log "$now *********[ DATABASE CHECK SCRIPT ENDED ]********\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$now never changes. how do you know date and time of each logline?