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.
my @cmdF = ("/etc/init.d/filebeat" "restart")instead, i.e. separat command and command arguments in different list entries. Otherwise sudo will look a file named/etc/init.d/filebeat restartto execute - which does not exist$ssh?