I am trying to use a perl one liner as
my $stat = $ssh->exec("perl -e /.firstboot | echo $?");
and what i want is to have $stat = 0 , if the file does not exist, and 1 f it does
but i am getting an error:
Search pattern not terminated at -e line 1.
Need some help please
Thanks,
-Kamal.
here is the whole script:
#!/usr/bin/perl
use Net::SSH::Expect;
use YAML;
use Data::Dumper;
use warnings;
use strict;
use diagnostics;
#####################
# process the input
#####################
my $in = YAML::LoadFile('test_input.yml');
my $version = $in->{test_instance}{version};
my $build = $in->{test_instance}{build};
my $host_data = $in->{host}[0];
my $modelnum = $host_data->{model_number};
my $company = $host_data->{company};
my $address = $host_data->{address};
#print Dumper($address), "\n";
my $ssh = Net::SSH::Expect->new(
ssh_option => "-v -v -v",
#ssh_option => "-v",
#host => $address,
host => "baseline-dc1",
#host => "upgrade-dc1",
#host => "upgrade-3d1",
#host => "baseline-3d1",
#host => "batterup-dc2",
user => 'admin',
#password => 'password',
raw_pty => 1,
#timeout => 2,
log_stdout => 1,
ssh_option => '-o StrictHostKeyChecking=no '
. '-o UserKnownHostsFile=/dev/null '
. '-o LogLevel=ERROR'
);
$ssh->run_ssh();
$ssh->exec("stty raw -echo");
#my $ls = $ssh->exec("ls -l /");
# print($ls);
# my $who = $ssh->exec("who");
# print ($who);
$ssh->send("sudo -i");
$ssh->waitfor('Password:', 3);
$ssh->send("Sourcefire");
print "logged in?\n";
my $catschedular = $ssh->exec("cat /sys/block/sda/queue/scheduler"
+);
my $echoconf = $ssh->exec("echo '/usr/lib/bigloo/3.1a' >> /etc/ld.
+so.conf");
my $catconf = $ssh->exec("cat /etc/ld.so.conf");
my $ldconfig = $ssh->exec("ldconfig");
print "the part we care about:\n\n\n";
my $stat = $ssh->exec("if [ -e /.firstboot ]; then echo 1; else echo 0
+; fi");
#my $stat = $ssh->exec("[ -f /.firstboot ] && echo "1" || echo "0"");
open OUT, "> /tmp/STAT.out";
print OUT $stat;
close OUT;
print "stat:|".$stat."|";
chomp $stat;
my $newstat;
$newstat = substr($stat, 0, 1);
$stat = $newstat;
print "new stat: |" . $newstat . "|\n";
print "old stat: |" . $stat . "|\n";
# testport returns 0 if the port accepts tcp connections
my $https=system("testport $address 443");
print "before..."."|".$https."|";
chomp $https;
print "after..."."|".$https."|";
The problem, is that
/tmp/STAT.out
contains the "prompt" in addition to "0" and i just want "0" which is the value of $stat
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.