I want to SSH to a server and execute a simple command like "id" and get the output of it and store it to a file on my primary server. I do not have privileges to install Net::SSH which would make my task very easy. Please provide me a solution for this. I tried using back-ticks but I am not able to store the output on the machine from which my script runs.
相关问题
- $ENV{$variable} in perl
- JavaScript File Transfer SSH
- Is it possible to pass command-line arguments to @
- Redirecting STDOUT and STDERR to a file, except fo
- Change first key of multi-dimensional Hash in perl
相关文章
- Check if directory exists on remote machine with s
- Running a perl script on windows without extension
- Git Clone Fails: Server Certificate Verification F
- Comparing speed of non-matching regexp
- Can NOT List directory including space using Perl
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- Extracting columns from text file using Perl one-l
- Can't access AWS CodeCommit with SSH
If you have ssh host keys setup you can simply run the ssh system command and then specify the command to run on the machine after that. For example:
You should be able to chomp/store that output.
You can always install modules locally, and that is the method you should look into; however, you should be able to get away with
If you're using backticks try this:
This is only useful if you have a publickey that the above command won't prompt for password.
Assuming that you're in an environment like me where you can't add additional modules and you can't create an Identity file, then you can use this script as a starting point.
If you can set up ssh keys then simply use the backticks command already posted, although you might need the -i option
or, assuming host keys are present and you want to do something with the command ouput ...
I know this is a very old thread, but since I encounter the same problem I found another useful solution in case that someone is using Linux.
This assumes that you have configured ssh-keys so no user input will be required. I did not want to have hard coded values this is the best way for me that worked the best. I am using readpipe to achieve that.
Hope this helps to have a solution in case of not hard coding.