i need to get rid of the new line which is the result of "wc -l" but neither chomp() nor chop() is working. Can anyone please help me Thanks, -Kamal. Javafan, i apologize for not providing a working script, this is my first time posting.my $cmd = 'ps efax 2>/dev/null|grep firstbo|grep -v grep|wc -l'; my $stat = $ssh->exec($cmd); print "Before chomp: " , length($cmd); print "|".$stat."|"; chop $stat; print "|".$stat."|"; print "After chomp: " , length($cmd);
result:#!/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 => 'OPTIONAL', 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"); $ssh->send("sudo -i"); $ssh->waitfor('Password:', 3); $ssh->send("password"); 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 $stat = $ssh->exec("ps efax 2>/dev/null|grep firstbo|grep -v grep|w +c -l | perl -pe 'chomp'"); open OUT, "> /tmp/STAT.out"; print OUT $stat; close OUT; print "stat: |" . $stat . "|\n"; chomp $stat; my $newstat; $newstat = substr($stat, 0, 1); $stat = $newstat; print "new stat: |" . $newstat . "|\n"; print "old stat: |" . $stat . "|\n";
as you can see that the last line is 0root@baseline-dc1:~# whereas it needs to be just a 0 hope this helps. i really appreciate ALL your comments and help.0root@baseline-dc1:~# stat: |0root@baseline-dc1:~# | new stat: |0| old stat: |0| before...|0|after...|0|bat@batbot:~/tests/Install_ISO$ more /tmp/STAT. +out 0root@baseline-dc1:~#
In reply to Getting rid of $/ on linux by kamal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |