How to login into the server using bash script?


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"
===

No comments:

Post a Comment