[英]Bash script to Batch convert .xlsx files to csv files using ssconvert after SFTP script
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.但是,在 SFTP 下载代码后在 Bash 脚本文件中添加相同内容时,它没有执行。 Please help.
请帮忙。 Thank you!
谢谢!
Bash script code - Bash 脚本代码 -
/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.使用 find 可能会导致未执行的东西,因为它可能会产生不继承父变量的子进程。 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:)免责声明:与 bash 一起使用 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.