1 #!/usr/bin/perl 2 print "hello"; 3 use strict; 4 use warnings; 5 use YAML_Lib; 6 use YAML::XS; 7 use Run_Lib; 8 9 print "hello 1"; 10 my $input_file; 11 if(scalar(@ARGV) < 1) 12 { 13 print("USAGE:: $0 \n"); 14 exit(0); 15 } 16 17 print STDOUT "Welcome to our little program\n"; 18 19 $input_file = $ARGV[0]; 20 print "Input File = $input_file\n"; 21 # parse the yaml file 22 $YAML_Lib::yaml_input = YAML::XS::LoadFile("$input_file"); 23 &YAML_Lib::parse_yaml($YAML_Lib::yaml_input); 24 25 # call client functions 26 &Run_Lib::socket_check(); #### 1 #!/usr/bin/perl 2 package Run_Lib; 3 use strict; 4 use warnings; 5 use Exporter 'import'; 6 use Net::OpenSSH; 7 #use Fcntl; 8 #use Client_Lib; 9 10 #function declarations 11 sub socket_check(); 12 sub open_file($$); 13 sub read_file_str($$); 14 sub write_file_str($$); 15 sub server_setup(); 16 17 #global variable declarations 18 my $client_connect_flag = 0; 19 my $pwd = $ENV{'PWD'}; 20 my $filename = "$pwd/LOG.txt"; 21 22 #check for if the socket is established by calling the client (host) script 23 #socket_check(); 24 25 sub socket_check() 26 { 27 # open the log file ( flush for the first time ) 28 print "helloooooooo!!"; 29 my $log_fh = open_file( $pwd, $filename ); 31 #write the log about calling client script 32 my $string = "INFO :: Calling the Client script \n"; 33 write_file_str( $log_fh, $string ); 34 35 # call the client functions to connect to the socket 36 #my $cmd = "$pwd/utpsm_lts_client.pl"; 37 #my $rc = system($cmd) 38 #or die "cant run client.pl $! \n"; 39 40 # my $socket_client = &Client_Lib::client_socket_create(); 41 # &Client_Lib::client_main($socket_client); 42 43 # check the log file if the client connected or not 44 my $client_str = "FAIL_CLIENT_CONNECT"; 45 read_file_str( $log_fh, $client_str); 46 47 # check if client connected or not 48 if ($client_connect_flag) 49 { 50 # setup the server on target 51 server_setup(); 52 } 53 54 } 55 56 sub open_file ($$) 57 { 58 my ( $pwd, $filename ) = @_; 59 my $FH; 60 open ( $FH ,"+>$filename" ) or 61 die "can't open/create $filename $!"; 62 return $FH; 63 } 64 65 66 sub read_file_str ($$) 67 { 68 my ($log_fh, $find_str) = @_; 69 my @lines = <$log_fh>; 70 #check for the output of log file if the client started or not 71 for (@lines) 72 { 73 if ($_ =~ /$find_str/ ) 74 { 75 $client_connect_flag = 0; 76 } 77 } 78 close $log_fh; 79 } 80 81 sub write_file_str ($$) 82 { 83 my ( $log_fh, $string_to_write ) = @_; 84 print $log_fh "$string_to_write"; 85 close $log_fh; 86 }