Saturday, August 9, 2008

Script Auto SCP/SFTP On Linux

We need a script that can send username / password in our Linux Box to transfer files through SFTP or SCP.

Requirement
1. OpenSSH
2. Expect

Illustrations :

We want to get "passwd" file on Server-A (192.168.1.1) and saved to /home/dianseh/passwd-Server-A on Server-B (192.168.1.2).

Server-B 192.168.1.2 ingin mengambil file di Server-A 192.168.1.1.
File Yang akan diambil dan disimpan adalah "passwd" dan di simpan pada direktori /home/dianseh pada server-B dengan nama file "passwd-Server-A"

The script is :

---- Script Start -----

#!/usr/bin/expect --
#spawn sftp dianseh@192.168.1.1:/etc/passwd /home/dianseh/passwd-Server-A
spawn scp dianseh@
192.168.1.1:/etc/passwd /home/dianseh/passwd-Server-A
expect "dianseh@
192.168.1.1's password:"
send "passwordnya\r"
expect "%$"


---- Script End -----

Note :
Let me know if it's working.

Good Luck

No comments: