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/bashset name "testnamefromfile"expect << 'EOS' spawn sftp -P 2222 admin@172.22.44.37:/var/log/datarecord expect "admin@172.22.44.37's password:" send "admin\n" expect "sftp>" send "get $name\r" expect "sftp>" send "bye\n"EOSThis 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""