I have Linux remote machine that running a script on the login attempt, which it will run the script, and its require the user input.
The main intention is to test the login user, the password with the auto-scripts response remotely when logon to that user.
Information inside the remote machine:
$ cat /etc/passwd
remoteuser:dontcare:dontcare:dontcare:dontcare:/usr/bin/somescript.sh
When user login into remoteuser, the somescript.sh will run.
The content of the script which asking for the user input
$ read -p '>' tmp
and I don't want to do any changes to that script.
Example of login
login: remoteuser
Password: remoteuserpassword
Quit Configuration (q, quit)
Is it possible for me to send the user input using ssh command? Currently my approach is using paramiko ssh,
connection = paramiko.SSHClient() using exec_command
but still it failed to send the input in right sequence or failed to passed to that script.
$ echo q
to the paramiko exec connection.exec_command('echo q')
I not using login as from root to test this remote user because it doesn't ask for password.
echo q | su - remoteuser
I ended up by using fabric.
and to execute that
Not, unless you change the script. SSH handles your script as a users shell (unless you have also some other configuration in
sshd_config
), which means that it runs it with the following arguments, if you provide some:This is the same way as it would be running any other arbitrary command in the users shell with
/usr/bin/bash -c "commnad"
. In your case it would look likebut most probably the arguments of the script are ignored. Your script waits for the commands on standard input and I believe you can provide that input in Paramiko too.