Aarish Ramesh
Aarish Ramesh

Reputation: 7023

Shell Script for automating pulling codes from a remote repository

Below is my simple shellscript for traversing through my project directories and pulling from a remote repository. Now I face a problem where the for loop stops executing when the remote repository asks for a password and i type it ie iteration through the directories stops. So i just want to know how do i continue iterating through the directories and repeat the procedure even after i enter the password and pull for a directory is completed!??

for item in *
do
if [ -d $item ]
then
    cd $item
    hg pull
fi
done

Upvotes: 0

Views: 593

Answers (1)

Ry4an Brase
Ry4an Brase

Reputation: 78330

You should just get passwords out of your workflow. If you're using HTTP then user the [auth] section of your hgrc, and if you're using ssh:// URL you should use ssh-agent.

Your loop, though would continue just fine after manually typing the password except that after the first one it's in the wrong directory and thus can't cd into the next repository. You need to cd .. after the hg pull. Or go with something like:

for repo in $(find . -type d -name .hg) ; do
     hg pull --repository $(dirname $repo) pull
done

That finds every repository below your current directory, no matter how deep, and does a pull on it -- it ignores directories and files that aren't repositories.

Upvotes: 2

Related Questions