Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my git auto-update Expect script work?

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.

  1. I am prompted for the info.
  2. The script successfully starts and continues reading the project_list.txt file.
  3. Once it finds itself in the repository's directory, it calls the githubexpect script and correctly passes on the info (I've tested this).
  4. githubexpect correctly spawns git push.
  5. It gets prompted for the input (I saw this in the console).
  6. It does provide my info (again, I saw this too).
  7. 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.

like image 729
corazza Avatar asked Dec 30 '12 17:12

corazza


1 Answers

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
like image 117
glenn jackman Avatar answered Oct 06 '22 00:10

glenn jackman