gpt4 book ai didi

shell 脚本停止工作 --- 需要重写吗?

转载 作者:行者123 更新时间:2023-12-04 19:23:51 24 4
gpt4 key购买 nike

下面的脚本在我的 Mac OS X 上运行。我现在使用的是 Ubuntu OS,脚本不再运行。我想知道这里是否有什么需要更改的地方?我确实将第一行从#!/bin/bash 更改为#!/bin/sh,但它仍然抛出一个错误......基本上,当我尝试运行它时出现错误:

Syntax error: end of file unexpected (expecting ")")

#!/bin/sh
REMOTE='ftp.example.com'
USER='USERNAME'
PASSWORD='PASSWORD'
CMDFILE='/jtmp/rc.ftp'
FTPLOG='/jtmp/ftplog'
PATTERN='SampFile*'

date > $FTPLOG
rm $CMDFILE 2>/dev/null

LISTING=$(ftp -in $REMOTE <<EOF
user $USER $PASSWORD
cd download
ls $PATTERN
quit
EOF )

echo "open $REMOTE" >> $CMDFILE
echo "user $USER $PASSWORD" >> $CMDFILE
echo "verbose" >> $CMDFILE
echo "bin" >> $CMDFILE
echo "cd download" >> $CMDFILE
for FILE in $LISTING
do
echo "get $FILE" >> $CMDFILE
done
echo "quit" >> $CMDFILE

ftp -in < $CMDFILE >> $FTPLOG 2>&1

rm $CMDFILE

编辑

我打开了 set -v 和 set -x ,看起来它没有运行 LISTING ......知道为什么吗?
REMOTE='ftp.example.com'
+ REMOTE=ftp.example.com
USER='USERNAME'
+ USER=USERNAME
PASSWORD='PASSWORD'
+ PASSWORD=PASSWORD
CMDFILE='/jtmp/rc.ftp'
+ CMDFILE=/jtmp/rc.ftp
FTPLOG='/jtmp/ftplog'
+ FTPLOG=/jtmp/ftplog
PATTERN='SampFile*'
+ PATTERN=SampFile*

date > $FTPLOG
+ date
rm $CMDFILE 2>/dev/null
+ rm /jtmp/rc.ftp

LISTING=$(ftp -in $REMOTE <<EOF
user $USER $PASSWORD
cd download
ls $PATTERN
quit
EOF )

echo "open $REMOTE" >> $CMDFILE
echo "user $USER $PASSWORD" >> $CMDFILE
echo "verbose" >> $CMDFILE
echo "bin" >> $CMDFILE
echo "cd download" >> $CMDFILE
for FILE in $LISTING
do
echo "get $FILE" >> $CMDFILE
done
echo "quit" >> $CMDFILE

ftp -in < $CMDFILE >> $FTPLOG 2>&1

rm $CMDFILE./inFullRefresh.sh: 34: Syntax error: end of file unexpected (expecting ")")

最佳答案

我认为 <<EOF让它寻找 EOF单独一行,EOF )不算。尝试改变

EOF )


EOF
)

关于shell 脚本停止工作 --- 需要重写吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2530042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com