I am trying to connect to a remote host as a user. Now i want to run a few commands that need sudo access. The commands are:
export http_proxy=http://xxxx.xx.xx.com:8080
export https_proxy=http://xxxx-xxxx.xx.xx.com:8080
sudo /etc/init.d/filebeat restart
sudo tail -f /var/log/filebeat/filebeat
I tried executing this using
my $ssh = Net::OpenSSH->new("$username\@$Hostname", password => $pass);
my @cmdF = "/etc/init.d/filebeat restart";
print "Restarting filebeat for $webHosts[$i]";
my @cmdF = "/etc/init.d/filebeat restart";
my $outputF = $ssh->capture({stdin_data=>"$pass\n"}, 'sudo', '-Sk', '-p', '', '-', @cmdF);
print "\nCurrent Filebeat Status : $outputF\n\n";
I took just one command at the moment but ended up getting this error:
sudo: /etc/init.d/filebeat restart: command not found
Please help me with the same for all commands..
Thank you in advance.
sudo /etc/init.d/filebeat restartconsists of three arguments (including the command):sudo/etc/init.d/filebeatrestartYou execute these instead:
sudo-Sk-p-/etc/init.d/filebeat restartMost relevant is that you combined two arguments into one, producing garbage.
What you need: