shell script stopped working --- need to rewrite?
The script below worked on my Mac OS X. I'm now using Ubuntu OS, and the script is no longer working. I'm wondering if there's something that I need to change here? I did change the first line from #!/bin/bash to #!/bin/sh, but it's still throwing up an error.... Essentially, I get an error when I try to run it:
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
EDIT
I turned set -v and set -x on and it looks like it's not running 开发者_高级运维the LISTING... Any idea why?
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 ")")
I think that <<EOF
makes it look for EOF
on a line by itself, and EOF )
doesnt count. Try changing
EOF )
to
EOF
)
精彩评论