Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$df_ret = `ssh -q rajesh 'df -hP'`; print "The value is $df_ret"; if ($df_ret =~ /\/boot/) { print "The value is $df_ret"; }
预期结果:
/dev/sda1 126931 39530 80848 33% /boot
但是,它即将全部df -k输出。任何的想法?
df -k
您的正则表达式与整个输出匹配为一个字符串。您可能希望先将其分成几行,然后再匹配每一行:
my @df_ret = `ssh -q rajesh 'df -hP'`; foreach my $line (@df_ret) { if ($line =~ m! /boot$!) { print "The value is $line"; } }
只需使用外壳:
ssh -q rajesh 'df -hP' | grep /boot