note
ncw
If you are using ssh then you are half way there!<P>
You need to generate yourself an identity using ssh-keygen
on the local machine. You then copy the public part of this
into the ~/.ssh/authorized_keys file on the remote server.<P>
You'll then be able to log into the remote machine without
using a password (provided you didn't set a password on
the identity you made).<P>
This requires that you keep your identity secret, but you
are proposing putting the username and password in a file
which is just as bad.<P>
This is the way I use ssh for all our system administration. We have a web page showing disk usage on all
or our servers generated in exactly this way.<P>
Once you've got it working you can do this
<CODE>
# ssh myremoteserver.net 'df -k'
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda3 17092820 2255644 13954808 14% /
/dev/sdb4 30639063 11498971 17533191 40% /home
</CODE>
Note the lack of login propmt!<P>
You need to take care passing commands to ssh - if you don't use
the list form of system you'll end up running your commands
through two shells (one remote, one local) which may be bad for your server health. Use like this
<CODE>
system("ssh", "-l", "root", "df -k") == 0
or die "Couldn't run command";
</CODE>
Take care with commands run on the remote server since they will be
run through the shell. Judicous use of ''s or \Q\E can help, or use [CPAN://Shell::StringQuote].
33314
33314