I know I should use certificate to automate this, but sometimes we do need to do scp with a password and it would be nice to automate it. Here Document does work. We need "expect" utility to do it. Here is an example:
#!/usr/bin/expect -f
# trick to pass in command-line args to spawn
#eval spawn scp $argv
eval spawn scp hcw root@10.0.0.1:.
expect "password: $"
send "yourpassword\n"
# wait for regular shell prompt before quitting
# probably a better way using 'wait'
expect "$ $"
Great solution I needed!!! Thanx, and keep up the good work :-)
ReplyDeleteRegards,
Marcel.
Thanks for the script.
ReplyDeletebut i am using the below script
#!/usr/bin/expect -f
# trick to pass in command-line args to spawn
#eval spawn scp $argv
eval spawn scp /home/bkpadm/* root@server1:/backup/agent
expect "root@server1's password: $"
send "password\n"
# wait for regular shell prompt before quitting
# probably a better way using 'wait'
expect "$ $"
In the script i am using * to move all the files but while executing the script it showing me the file doesnot exist error.
My files are in the name format of below `date "+%d-%m-%y"`.tar.gz
hence i need to move the files on daily basis thats why i am using * to move all the files.
Thanks & Regards,
Nareen T