· 8 years ago · Nov 11, 2016, 07:10 PM
1###########################
2## LOG SCRIPT ##
3## Written by :- AMAR ##
4###########################
5
6#!/usr/bin/perl
7
8use Net::SSH::Expect;
9use POSIX qw(strftime);
10
11$server = "192.168.1.122";
12$username = "amar";
13$passwd = "Sample\@123";
14
15my $now = strftime('%d-%m-%Y %H:%M:%S',localtime);
16
17open ($Log,"+>>","/home/amar/logs/Sample.log");
18print $Log ("$now ***********[START OF SCRIPT : DATABASE CHECK]***********\n");
19print $Log ("$now Trying to connect to the Server : $server\n");
20
21$ssh = Net::SSH::Expect->new(host => "$server",password => "$passwd",user => "$username",raw_pty => 1, timeout => 2);
22
23$login_output=$ssh->login();
24if ( $login_output !~ /Last login:/)
25{
26 print "Failed to login into the Server : $server\n";
27 print $Log ("$now Failed to login into the Server : $server, Check the credentials\n");
28}
29else
30{
31 print $Log ("$now Logged into the Server : $server\n");
32
33 ## PERFORM UR ACTIVITY .....
34
35 print "Database check was successful\n";
36 print $Log ("$now DatabasE check was successful\n");
37}
38
39print $Log "$now *********[ DATABASE CHECK SCRIPT ENDED ]********\n";