I want to create a script so that I copy the newest file from an SFTP server, for that I have created a script that gets the name and put the name in a file.
Now I want to create another script to download the newest file which I have the name, but I am struggling with passing the content of my file to a variable and then downloading that file.
#!/bin/bash
set name "testnamefromfile"
expect << 'EOS'
spawn sftp -P 2222 [email protected]:/var/log/datarecord
expect "[email protected]'s password:"
send "admin\n"
expect "sftp>"
send "get $name\r"
expect "sftp>"
send "bye\n"
EOS
This is my script. How can I assign the content of the file to the $name variable? And how to download that file?
When I run this script it throws out below error:
sftp> can't read "name": no such variable
while executing
"send "get $name\r""