I wanted to make a script that would update all of my GitHub repositories.
I would just need to enter my Username and my Password, and the script would go through a list of repositories, call git push
and provide the necessary information via a supplementary Expect script.
This is my bash script:
#! /bin/bash
echo "Updating GitHub projects from project_list.txt."
echo
read -p "GitHub username: " un
read -p "GitHub password: " -s pw
echo
echo
while read line
do
eval dir=$line
echo "Updating:" $dir"."
cd $dir
$SF/githubexpect $un $pw
echo
echo
done < $SF/project_list.txt
$SF
is a global environment variable that contains an absolute path to my script folder.
Here is the githubexpect script:
#! /usr/bin/expect
set un [lindex $argv 0]
set pw [lindex $argv 1]
spawn git push
expect "Username"
send $un\n
expect "Password"
send $pw\n
When I run the bash script, things go as expected.
project_list.txt
file.git push
.I am suspecting that the githubexpect script might be spawning git push
relative to itself, and not the directory the current script is being executed in, so git doesn't even find a repository. This is probably false though as my script folder, in which githubexpect resides, is a repository as well.
You should be sending \r
instead of \n
. However the real problem is you don't wait for git push
to complete. Add this as the last line of the expect script
expect eof
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With