“expect” is a means of automating dialogue in the bash console.
sudo apt-get install -y expect
When doing git push to GitHub, interactivity occurs. Username and password.
We’ll automate this input to make it automatic.
#!/usr/bin/expect
set USER [lindex $argv 0]
set PW [lindex $argv 1]
set Prompt "\[#$%>\]"
set timeout 5
spawn git push
expect {
-glob "Username for 'https://github.com':" {
send -- "${USER}\n"
}
}
expect {
-glob "Password for 'https://${USER}@github.com':" {
send -- "${PW}\n"
}
}
expect {
-glob "${Prompt}" {
# interact
exit 0
}
}
How to Use
- Rename the above script to something like
~/lib/github.exp - $ ~/lib/github.exp USERNAME PASSWORD
- You can push to GitHub. (As a prerequisite, create a repository. If "Everything up-to-date" etc. is displayed, it's ok)
Reference: http://qiita.com/ine1127/items/cd6bc91174635016db9b