urello has asked for the wisdom of the Perl Monks concerning the following question:

Pls advise how to get this code working
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my $host = $ARGV[0]; my $ssh2 = Net::OpenSSH->new($host,user=>'root',timeout=>600); my @usernames = $ssh2->capture("du -s /var/lib/mysql/* |sort -nrk1 |aw +k -F'[\t_/]' '{if(\$1 > 100000) print \$(NF-1)}' |sort -u |grep -v 'm +ysql'"); foreach my $tempo (@usernames) { my @domains = $ssh2->capture("grep $tempo /etc/userdomains|cut + -d: -f1"); #THIS IS NOT WORKING SINCE $TEMPO IS NOT DEFINED IN SHELL foreach (@domains) { print "TEST $_"; } }

Replies are listed 'Best First'.
Re: How to pass variable to Net::OpenSSH method
by hdb (Monsignor) on Apr 22, 2015 at 08:00 UTC
    my @domains = $ssh2->capture("grep $tempo /etc/userdomains|cut -d: -f1"); #THIS IS NOT WORKING SINCE $TEMPO IS NOT DEFINED IN SHELL

    The comment is misleading as $tempo will already be substituted by Perl with each element of @usernames in turn. The shell will never be asked for a variable $tempo.

    You might want to inspect @usernames to see what you got from the first capture command.

Re: How to pass variable to Net::OpenSSH method
by salva (Canon) on Apr 22, 2015 at 07:25 UTC
    How does it fail to work?

    Net::OpenSSH has a debugging mode that you can enable adding the following line at the beginning of your script:

    $Net::OpenSSH::debug = -1;