You are not logged in.
Hello,
I got a bash script that I'd like have as one script and not have to spawn another script in the shell and was wondering if there was a way to do this. I'll just post the script here so you have an idea what I'm doing.
I'm trying to run a github sync script. To be able to do this though, I need to run a another script that runs 'expect'. Expect is a program that read terminal input and then responds when a certain field is read. In this case, it run ssh-add and then automatically enters my ssh passphrase:
#!/usr/bin/expect
# ssh-agent-pass - Add rsa passphrase to ssh-agent
spawn ssh-add /home/gen2ly/.ssh/id_rsa
expect "id_rsa':"
# send reply (takes about five seconds)
send "thisisreallymysecretpassphrase;)\n"
expect eof
exit
and the github-sync script:
#!/bin/bash
# github-sync - sync files to github
locrepohome="~/.github-home/"
cd $locrepohome
git add $locrepohome # take snapshot of all contents in current dir
git commit -a -m "weekly update - $(date "+%F")"
eval `ssh-agent` # Start ssh-agent and enter passphrase automatically
ssh-agent-pass
git reset --hard # delete remote repository for matching sync
git push # push changes to remote repository
I'd like to simply things and have everything in one script. Is this possible?
Last edited by Gen2ly (2009-10-24 20:22:22)
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Just a guess:
#!/bin/bash
# github-sync - sync files to github
locrepohome="~/.github-home/"
cd $locrepohome
git add $locrepohome
git commit -a -m "weekly update - $(date "+%F")"
eval `ssh-agent`
echo "spawn ssh-add /home/gen2ly/.ssh/id_rsa\nexpect \"id_rsa':\"\nsend \"thisisreallymysecretpassphrase;)\\n\"\nexpect eof\nexit" | expect
git reset --hard # delete remote repository for matching sync
git push # push changes to remote repository
Offline
Try
#!/bin/bash
# github-sync - sync files to github
locrepohome="~/.github-home/"
cd $locrepohome
git add $locrepohome # take snapshot of all contents in current dir
git commit -a -m "weekly update - $(date "+%F")"
eval `ssh-agent` # Start ssh-agent and enter passphrase automatically
expect <<EOF
spawn ssh-add /home/gen2ly/.ssh/id_rsa
expect "id_rsa':"
# send reply (takes about five seconds)
send "thisisreallymysecretpassphrase;)\n"
expect eof
exit
EOF
git reset --hard # delete remote repository for matching sync
git push # push changes to remote repository
Last edited by some-guy94 (2009-10-24 19:32:24)
Offline
Barrucadu, that's awesome! I had a lingering thought that it might not work, I thought that only certain especially commands could be piped too. I did have to tell expect to... expect a file :
eval $(ssh-agent)
entpass=$(echo "spawn ssh-add /home/gen2ly/.ssh/id_rsa
expect \"Enter passphrase for key.*\"
send \"realunknownpass\\n\"
expect eof" | expect -f -)
echo $entpass
And everything is working good now. !!!
Someguy. I tried yours too but the command exited before it could do anything:
Could not open a connection to your authentication agent.
Thanks for the help guys.
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
why don't you just use an ssh-agent which works on your entire desktop session? i just unlock my keys when i login, so i can use my keys the whole time.
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
@ Dieter@be - If I did that though, wouldn't I have to type in a password every time I logged into a bash shell? If I remember correctly, I'd have to put this in my .bashrc, right?
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
@ Dieter@be - If I did that though, wouldn't I have to type in a password every time I logged into a bash shell? If I remember correctly, I'd have to put this in my .bashrc, right?
once you unlock your keys your agent will remember then. it's then just a matter of making sure the "scope" of your agent is correct, and not launching new agents.
have a look at http://bbs.archlinux.org/viewtopic.php?id=81622, there are also various resources about this on the interwebs.
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline