I am getting empty values for the variable $tclItem in the below script in foreach loop even though the list contains values.
Could you please check and see what am i missing?
FTP_USER="xxxxx"
FTP_SERVER="xxxxx"
FTP_PWD="xxxx"
FTP_DROP_DIR="DROP/Archive"
LOGFILE="\tmp\log.txt"
FILES_TO_ARCHIVE="$(cat $LOGFILE | grep '.txt' | awk ' !/Fetching/' | tr -d '\r') "
echo "Files to Archive..."
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo $FILES_TO_ARCHIVE
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
expect <<END
spawn sftp $FTP_USER@$FTP_SERVER
expect "*password: "
send "$FTP_PWD\r";
expect "sftp> "
foreach tclItem {$FILES_TO_ARCHIVE } {
#puts $tclItem
send "ls $FTP_DROP_DIR/$tclItem\r"
expect "sftp> "
};
send "quit\r"
END
and here is the output that i am receiving.
Files to Archive.....
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
test1.txt test2.txt test3.txt test4.txt
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
spawn sftp [email protected]
abcdef@sftp's password:
sftp> ls DROP/Archive/
sftp> ls DROP/Archive/
sftp> ls DROP/Archive/
sftp> ls DROP/Archive/
sftp> invalid command name "test2.txt"
while executing
"test2.txt"
lftp? Or the Python paramiko library'ssftptooling will similarly be a better tool for the job than expect+sftp.expectis invoked. So by the time theforeach tclItemis run byexpect,$tclItemwas already replaced with an empty value by the shell interpreter at heredoc evaluation time.puts [list $FILES_TO_ARCHIVE]-- what is the output?