Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 159

Expect script - sending filename with a variable

$
0
0

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"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""

Viewing all articles
Browse latest Browse all 159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>