Created
March 13, 2010 08:42
-
-
Save khamanaka/331206 to your computer and use it in GitHub Desktop.
sshでログインするシェルスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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