I am writing an Expect script to pull the latest code from our dev server each time a new server instance is spawned on AWS. The idea is that when the new server is created, the script is run at boot before being placed behind the load balancer. It works perfectly unless Git aborts because of a conflict. Here is the code so far:
#!/usr/bin/expect -f
set timeout 240
spawn /xyz/pullfromdev
expect "*?assphrase*"
send -- "<mypass>\r"
expect {
"Aborting" {
set response $expect_out(buffer)
set format [split $response "\n"]
cd /var/www/html
foreach line $format {
if { !([string range $line 0 8] == "Identity " || [string range $line 0 8] == "Updating " || [string range $line 0 5] == "error:" || [string range $line 0 6] == "Please," || [string range $line 0 7] == "Aborting" || [string length $line] == 1 ) } {
open "| git checkout -- [string trim $line]"
}
}
spawn /xyz/pullfromdev
expect "*?assphrase*"
send -- "<mypass>\r"
}
}
expect eof
Basically I am splitting the output buffer and trying to run git checkout -- <filename> for each file that has a conflict. Then trying to pull again to hopefully complete successfully.
The issue is with the line:
open "| git checkout -- [string trim $line]"
It simply does not perform any action apparently and i do not get any error. The script tries to pull again from the dev server and aborts because the git checkout did not occur and the conflicts remain. TCL is a bit foreign to me so perhaps its a syntax issue? I have tried spawn as well as exec but they do not seem to work either. Conflicts remain and git aborts.
However, if I run git checkout -- <filename> via the command line, then that particular file is no longer conflicting (because the checkout actually occurred). So the issue really is getting the git checkout command to run from the Expect script which i am failing to do somehow.
Does anyone have any suggestions?
If it helps at all, this is on CentOS 5 and the 'pullfromdev' script referenced in the code is simply:
#!/bin/bash
cd /var/www/html
ssh-agent bash -c 'ssh-add /xyz/<identity>; git pull'