Automatic scp command

Secure Copy or SCP is a means of securely transferring computer files between a local and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. When we use this command, we must prompt password to copy file from other host. We can use upload public key for automatic, but we can use other method to bypass input password.

Expect is a useful tool for feeding inputs automatically to an interactive program. Expect  is a program that “talks” to other interactive programs accord‐ing to a script. This is a sample code to bypass password when use scp command :

#!/usr/bin/expect

set timeout 30
spawn /usr/bin/scp /home/toto/rsfrunning.sh angel@192.168.99.102:/home/angel/
expect {
        "password:"
       {
          send "your_password\r"
          interact
       }
}

This is a simple script to bypass command from konsole. You can use other command (ex. ssh, ftp, etc) with expact, so you can bypass other parameter from that command.

Source :
http://wiki.tcl.tk/11583
http://myithaca.wordpress.com/2009/06/21/expect-scripting-tutorial/

Add a Comment

Your email address will not be published. Required fields are marked *