Skip to content

Instantly share code, notes, and snippets.

@khamanaka
Created March 13, 2010 08:42
Show Gist options
  • Save khamanaka/331206 to your computer and use it in GitHub Desktop.
Save khamanaka/331206 to your computer and use it in GitHub Desktop.
sshでログインするシェルスクリプト
#!/bin/sh
USER="user"
PASSWD="password"
HOST="ipadress"
PORT=123456
X_CMD(){
local U=$1 ; shift
local PW=$1 ; shift
local H=$1 ; shift
local P=$1 ; shift
local PR='(#|\\$) $'
expect -c "
set timeout 20
spawn ssh -l $U $H -p $P
while (1) {
expect timeout { break } \"(yes/no)?\" { sleep 1;send \"yes\r\" } \"word: \" { sleep 1;send \"$PW\r\" } -re \"$PR\" { sleep 1;send \"\r\";break }
}
"
}
X_CMD $USER $PASSWD $HOST $PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment