scp using script

Hi all,
I want to setup scp script for copying files to remote server.
I did google and all refereed expect, but the script failed to work.

Please lead me to some useful link or piece of script.

Thanks in advance,

This is normal script to copy from machine1 to machine2.

scp pax@machine1:/tmp/qq pax@machine2:/tmp/qq

what you are trying to do..?

Something like :

But except completely new for me..and it failed to wok.

#!/usr/bin/expect -f                                                                                                                                  

# connect via scp                                                                                                                                     
spawn scp "pooja@lxplus.cern.ch:/afs/cern.ch/user/p/pooja/README" /home/poojasaxena/Desktop/CMS/script/ShellScripts/
#######################                                                                                                                               
expect {
  -re ".*es.*o.*" {
    exp_send "yes\r"
    exp_continue
  }
  -re ".*sword.*" {
    exp_send "PASSWORD\r"
  }
}
interact

Or i would say that the password should be provided by the script itelf. And the SCP should be automatic, once script is executed.

try using this..

#!/usr/bin/expect
        spawn scp  /mnt/backup.tar root@235.658.158.325:/home
        set pass "REHRKJH564564"
        expect {
        password: {send "$pass\r"; exp_continue}
                  }

source code

Error:

 bash: ./RemoteFilesv3.sh: /usr/bin/expect: bad interpreter: No such file or directory

Have you tried using correct path..

expect is not present in my machine so can't help you with that..:o

Hey,
it worked..:slight_smile: Thanks. I just had to install expect..:smiley:

Have you tried using ssh keys? That you had to install the third-party expect brute-forcing tool is a subtle hint, in mile-high glowing neon letters, that your plan is a rather bad idea. It's very hard to keep retrievably stored passwords safe. ssh, scp, sftp, su and the like are making it difficult for you, not because they hate you, but as a security feature to prevent what you're trying to do.

Hi Corona,
I tried that long back when I was working with ubuntu 10.04 . Did not succeed.
Now I have upgraded to 12.04.. possibly, I should try again.

Thanks,

---------- Post updated at 03:30 PM ---------- Previous update was at 10:11 AM ----------

Hi,

#!/usr/bin/expect                                                                                                                                   
                                                                                                                                                      
#$TARGET=/uscms/home/pooja04/script/AnalysisCode/Code42012/                                                                                           

spawn scp userd04@remote.server://file*root .
set pass "pass"
expect {
    password: {send "$pass\r"; exp_continue}
}

It is not copying all the file with extension *root. It just copied single file and then stopped.:confused: