问题
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.
- I am prompted for the info.
- The script successfully starts and continues reading the
project_list.txt
file. - Once it finds itself in the repository's directory, it calls the githubexpect script and correctly passes on the info (I've tested this).
- githubexpect correctly spawns
git push
. - It gets prompted for the input (I saw this in the console).
- It does provide my info (again, I saw this too).
- Then it just continues on to the next repository like nothing happened. <-- Error!
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.
回答1:
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
来源:https://stackoverflow.com/questions/14092636/why-doesnt-my-git-auto-update-expect-script-work