Advertisement
Guest User

Untitled

a guest
Nov 11th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. ###########################
  2. ## LOG SCRIPT ##
  3. ## Written by :- AMAR ##
  4. ###########################
  5.  
  6. #!/usr/bin/perl
  7.  
  8. use Net::SSH::Expect;
  9. use POSIX qw(strftime);
  10.  
  11. $server = "192.168.1.122";
  12. $username = "amar";
  13. $passwd = "Sample\@123";
  14.  
  15. my $now = strftime('%d-%m-%Y %H:%M:%S',localtime);
  16.  
  17. open ($Log,"+>>","/home/amar/logs/Sample.log");
  18. print $Log ("$now ***********[START OF SCRIPT : DATABASE CHECK]***********\n");
  19. print $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();
  24. if ( $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. }
  29. else
  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.  
  39. print $Log "$now *********[ DATABASE CHECK SCRIPT ENDED ]********\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement