The below command works perfectly fine in command line mode
find . -maxdepth 1 -name "*.xlsx" -exec ssconvert {} --export-type=Gnumeric_stf:stf_csv \;
But while adding the same in a Bash script file after SFTP download code, it isn't executing. Please help. Thank you!
Bash script code -
/usr/bin/expect<<EOD
spawn /usr/bin/sftp -o Port=${PORT} username@hostname
expect "password:"
send "$Pass_Pwd\r"
expect "sftp>"
send "lcd ${Src_Dir}\r"
expect "sftp>"
send "mget ${File1}\r"
expect "sftp>"
send "mget ${File1}\r"
expect "sftp>"
send "bye\r"
EOD
echo "Download done"
find . -maxdepth 1 -name "*.xlsx" -exec ssconvert {} --export-type=Gnumeric_stf:stf_csv \;
Using find may result in non executed stuff because it may spawn subprocesses which don't inherit parent variables. From what I see in your code, this shouldn't happen, but:
Anyway, here's a hardened example of what you might want to code:
workdir = /data/ftpdownloads
cd "$workdir" || { echo 'Failed to chdir into $workdir' ; exit 1; }
# Insert your expect script here
while IFS= read -r -d $'\0' file; do
ssconvert "$file" --export-type=Gnumeric_stf:stf_csv
done < <(find "$workdir" -type f -iname "*.xlsx" -print0)
Disclaimer: Use with bash :)