user3664498
user3664498

Reputation: 11

Expect in shell

I am using an expect code to scp a file to remote location. Below is the code :

#!/usr/bin/expect
set DATE [clock format [clock seconds] -format {%Y_%m_%d}]
set VAR /LDAPBackup/binbak/Meta1/binbak_$DATE.tar
spawn scp $VAR [email protected]:/home/netscape/scripts/file_scp
expect "Password:"
send "*$stg\r"
expect eof
exit

The error i am encountering is as below :-

spawn scp /LDAPBackup/binbak/Meta1/binbak_2015_05_03.tar [email protected]:/home/netscape/scripts/file_scp
`Password: can't read "stg": no such variable while executing
"send "*$stg\r""
(file "./scp_dev" line 6)`

Can anyone tellme the correct way to do it.

Upvotes: 0

Views: 63

Answers (2)

user3664498
user3664498

Reputation: 11

Below can work :-

expect "Password:"
send "*\$stg\r"

Upvotes: 1

SMA
SMA

Reputation: 37023

You could use sshpass like:

sshpass -p $password scp $VAR [email protected]:/home/netscape/scripts/file_scp

Or if password is in file then:

sshpass -p $filename_with_password scp $VAR [email protected]:/home/netscape/scripts/file_scp

Upvotes: 0

Related Questions