ABCXYZ123-0-0-1:/home/dir-> hostname | sed 's/-.*?//g'
ABCXYZ123
####
#!C:/Perl64/bin/perl.exe
use strict;
use warnings;
use Control::CLI;
my $cli;
my $output;
my $temp;
my $junk;
#my $host = "1.11.1.11";
my $host = "1.12.1.12";
$cli = new Control::CLI( Use => 'SSH',
Timeout => 180,
);
$cli->connect( Host => $host,
Username => 'user',
Password => 'pass',
);
$output = $cli->cmd("clear");
$output = "";
my $hostname = $cli->cmd("hostname | sed \'s/-.*//g\'");
print "hostname: $hostname";
$junk = $cli->print("su -c \"/some/dir/path/here/command.py -o /dir\"");
$output = $cli->cmd("rootpwd");
print "\n$output\n";
#if ( $output =~ m/.*$hostname.ext.*/s && $output =~ m/.*name.ext.*/s ) {
if ( $output =~ m/$hostname/s ) {
print "\t$hostname.ext and name.ext created successfully on server in /spdata...\n";
} else {
print "\tThere was a problem generating $hostname.ext and name.ext on server in /spdata... Please investigate and start application again... Exiting program.\n";
exit;
}
$cli->disconnect;
####
C:\Users\ImJustAFriend\Documents\Perl\Test>CLIControlTest.pl
hostname: ABCXYZ123
Password:
Last login: Mon Jan 13 13:26:40 UTC 2014 from blah on ssh
/spdata/ABCXYZ123.ext is generated
/spdata/name.ext is generated
There was a problem generating ABCXYZ123
.ext and name.ext on server in /spdata... Please investigate and start application again... Exiting program.
C:\Users\ImJustAFriend\Documents\Perl\Test>
####
C:\Users\ImJustAFriend\Documents\Perl\Test>CLIControlTest.pl
hostname: ABCXYZ123
Password:
Last login: Mon Jan 13 13:26:40 UTC 2014 from blah on ssh
/spdata/ABCXYZ123.ext is generated
/spdata/name.ext is generated
.ext and name.ext on server in /spdata... Please investigate and start application again... Exiting program.
C:\Users\ImJustAFriend\Documents\Perl\Test>