Here is the script :
===
#!/bin/bash
HOST="remote-hostname"
USER="remote-user"
PASS="remore-user-password"
CMD=$@
VAR=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD
match_max 100000
expect \"*?assword:*\"
send -- \"$PASS\r\"
send -- \"\r\"
expect eof
")
echo "==============="
echo "$VAR"
===
Try :)
it shows command not found
ReplyDeleteYou need to assign the values of the following variables like :
ReplyDeleteHOST
USER
PASS
Then try to execute and let me know the results.
it logs in and then logs out.. uve just put $VAR in an echo command. so it jus displays rite? how to be in that shell?
ReplyDeleteBetter & more secure way to do that would be 1stly to setup an
ReplyDeletessh key with no passphase.
then instead of using the spawn & expect commands just use plain old ssh
to pass the command to the remote server
# ssh user@srv.domain.com 'command to run on remote server'
What ever is inside the ' ' (single quotation marks) will be executed
on the remote server