2

i am trying to get a list of files from secure server to compare them (using diff) to the ones i modified on local version (unfortunately the company i work in is not using subversion nor git yet)

i get list of files easily with:

find . -mtime -20 | grep "\.php\|\.js\|\.css" > changedfiles.log

what i need is a script which would loop over this list and secure copy each of them (scp or rsync) to a local directory, preserving relative path name. i tried:

for line in `cat changedfiles.log`
do
 DIRPATH=`dirname "$line"`
 `mkdir -p myfiles/$DIRPATH`
 scp user@host:/remotepath/$line myfiles/$line
done

but scp keeps asking me for the password (i dont want to setup key-based authentication to scp without password)

i am not allowed to ssh on remote server so i cannot just zip the list and download them in one command

is it possible to do something to input password only once?

3

Rather than set up a passphraseless key, create a passphrase-protected key and use ssh-agent to ensure you only need to enter it once per job.

After generating your keys, prefix your script with something like this:

# Start a new agent
eval `ssh-agent -s`

# add keys with a two-hour time limit
ssh-add -t 7200 ~/.ssh/id_rsa

At this point, you'll be prompted for your passphrase. After your script is finished, you can have ssh-agent be killed automatically if you do not wish to let it continue to run:

# kill the agent
ssh-agent -k

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.