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

时间:2010-03-27 16:39:23

标签: shell ubuntu scripting

下面的脚本适用于我的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

修改

我转动设置-v并设置-x on,看起来它没有运行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 ")")

1 个答案:

答案 0 :(得分:1)

我认为<<EOF使其在一行上查找EOF,而EOF )并不重要。尝试更改

EOF )

EOF
)