currently, i have statements like : system("ssh -o StrictHostKeyChecking=no root\@${address} \"cat /var/log/messages""); This did not require a password, since the two systems were setup with proper key exchange
now this is no longer available: hence:
i want to be able to :
- Login as "admin"
- Supply a password
- do a sudo -i
- supply a password
- run the same command "cat /var/log/messages"
Thanks, -Kamal.
When using Perl, always look for a module in CPAN for the task. Almost certainly someone has already solved your problem. In this case: Net::SSH::Perl.
Rather than use sudo, you can probably just add the "admin" user to the group of the /var/log/messages file. On a typical Debian/Ubuntu system, this would mean adding the "admin" user to the "adm" group, since that is the group of the /var/log/messages file.
To add the admin user to the "adm" group:
Then, just use ssh without sudo to cat the file.
Another option is to edit your /etc/sudoers file (using visudo) to allow the admin user to run that command without a sudo password.
use Net::OpenSSH.
On the samples directory from the module distribution you will find some scripts automating sudo interaction.