I want to SSH on a server and execute a simple order like "id" and get its output and Archiving It does not have the privilege to set up a file on my primary server that will make my work very easy. Please give me a solution for this I tried to use back-tiex but I am not able to store the output on the machine on which my script runs.
The best way to use SSH to run a command remotely
< Code> $ ssh user @ host "command" & gt; Output.file
You can use it in either Bash or Pearl, however, if you want to use perl, then you can install Perl module in your local directory path As suggested by the brain in its comments or "Perl FAQ". Instead of using Net :: SSH, I can suggest using Net :: SSH :: Perl with the following example.
#! Use / usr / bin / perl -w hard; Use Lib qw ("/ path / to / module /"); Net :: SSH :: Use Perl; My $ hostname = "hostname"; My $ username = "username"; My $ password = "password"; My $ CMD = shift; My $ ssh = Net :: SSH :: Perl- & gt; New ("$ hostname", debug = & gt; 0); $ SSH- & gt; Login ("$ username", "$ password"); My ($ stdout, $ stderr, $ exhaust) = $ ssh- & gt; Cmd ("$ cmd"); Print $ stdout;
Comments
Post a Comment