Skip to content

Instantly share code, notes, and snippets.

@wangmuy
Last active August 30, 2016 02:16
Show Gist options
  • Save wangmuy/5b13b2de587e60554583e3e8d0c80dc1 to your computer and use it in GitHub Desktop.
Save wangmuy/5b13b2de587e60554583e3e8d0c80dc1 to your computer and use it in GitHub Desktop.
sshpass supply password in commandline
#!/usr/bin/expect -f
# http://stackoverflow.com/questions/28051969/tcl-expect-equivalent-of-bash-or-how-to-pass-arguments-to-spawned-process-in
# usage:
# sshpass.sh userpwd ssh [email protected] 'nohup sleep 30 </dev/null >/dev/null 2>&1 &'
# sshpass.sh userpwd scp svn-auth-file.bak [email protected]:/home/user/svn-auth-file.bak
set PWD [lindex $argv 0]
set ARGS [lrange $argv 1 end]
spawn {*}$ARGS
expect "*password:*"
send "$PWD\r"
expect eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment