My recommendation is also to use something like
Net::OpenSSH as mentioned by my fellow Monks, but coupled with
$HOME/.ssh/config so that you remove the need to manage (most if not all) ssh options inside of your script. So
<remotehost> becomes
<ssh_config_alias> in your
DWIW illustration above.
In addition to this, there is nothing wrong with uploading a script file directly into $HOME/tmp then executing that script. In many ways this is much more clear and will be more easily understood by your future self during any maintenance of this program.
Finally be sure to protect the script appropriately, for example I would not blindly upload it to /tmp and I would ensure that only the remote system $USER is able to read the script. Also, clean up after by deleting the script.
For additional security, you may pass sensitive values to the script via the environment using the equivalent of ssh -o SendEnv=MYVAR directly or in your code. Any passwords or other secrets may be provided to the script this way and the script would just make use of them assuming they are defined. Do not send them to the script via commandline argument or by explicitly setting the value in the ssh command itself.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.