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.

1. OpenSSH
2. Expect

Illustrations :

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

Server-B ingin mengambil file di Server-A
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@ /home/dianseh/passwd-Server-A
spawn scp dianseh@ /home/dianseh/passwd-Server-A
expect "dianseh@'s password:"
send "passwordnya\r"
expect "%$"

---- Script End -----

Note :
Let me know if it's working.

Good Luck

No comments: