下面是我写的shell脚本:到if [ $path -eq $(date +%Y%m03) ]行就报错:
#! /bin/sh
path=$(date +%Y%m%d)
echo "path=$path $(date +%Y%m03)"
echo "$(date -d"1 month ago" +"%Y%m01")"
cd /home/smp/RECEIPT/
mkdir $path
yesterday=$(date -d"1 day ago" +"%Y%m%d")
month=$(date -d"1 month ago" +"%Y%m01")
ftp -n IP <<!
user 用户名 密码
bin
cd ftp服务器的路径
lcd 本机指定路径
prompt
if [ $path -eq $(date +%Y%m03) ]
then
echo("true")
mget *SMFWC_971_01DY_$yesterday* *SMPGD_971_01MO_$month* *SMPSR_971_01MO_$month*
else
echo("false")
mget *SMFWC_971_01DY_$yesterday*
fi
bye
!
脚本运行日志如下:
path= 20131103
20131001
mkdir: 缺少操作数
请尝试执行“mkdir --help”来获取更多信息。
yesterday's date
Connected to IP.
220 wg_tx2 FTP server (Version 4.2 Fri Feb 3 22:13:23 CST 2006) ready.
331 Password required for tonglink.
230-Last unsuccessful login: Mon Nov 4 12:20:33 2013 on /dev/pts/4 from IP
230-Last login: Mon Nov 4 12:20:33 2013 on /dev/pts/4 from IP
230 User tonglink logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
200 Type set to I.
250 CWD command successful.
Local directory now /home/smp/RECEIPT
Interactive mode off.
?Invalid command.
?Invalid command.
?Invalid command.
。。。。。获取到的文件
226 Transfer complete.
82 bytes received in 00:00 (1.50 MB/s)
?Invalid command.
221 Goodbye.
求大神指点,为什么会?Invalid command.,应该怎么修改!急!在线等待!
问题出在echo("true") 或者echo("false")这一句,ftp里面不支持,你手动执行一下就知道了。
ftp> echo("true")?Invalid command
ftp> help
Commands may be abbreviated. Commands are:
! debug mdir sendport site
$ dir mget put size
account disconnect mkdir pwd status
append exit mls quit struct
ascii form mode quote system
bell get modtime recv sunique
binary glob mput reget tenex
bye hash newer rstatus tick
case help nmap rhelp trace
cd idle nlist rename type
cdup image ntrans reset user
chmod lcd open restart umask
close ls prompt rmdir verbose
cr macdef passive runique ?
delete mdelete proxy send追问
这块是有问题,删除后运行,还是会提示?Invalid command
追答你在ftp那段here doc里面,使用shell的语法都是不行的。
if [ $path -eq $(date +%Y%m03) ]
then
fi
这些都算?Invalid command的。
你这样改
#! /bin/shpath=$(date +%Y%m%d)
echo "path=$path $(date +%Y%m03)"
echo "$(date -d"1 month ago" +"%Y%m01")"
cd /home/smp/RECEIPT/
mkdir $path
yesterday=$(date -d"1 day ago" +"%Y%m%d")
month=$(date -d"1 month ago" +"%Y%m01")
if [ $path -eq $(date +%Y%m03) ]
then
ftp_cmd="mget *SMFWC_971_01DY_$yesterday* *SMPGD_971_01MO_$month* *SMPSR_971_01MO_$month*"
else
ftp_cmd="mget *SMFWC_971_01DY_$yesterday*"
fi
ftp -n IP <<!
user 用户名 密码
bin
cd ftp服务器的路径
lcd 本机指定路径
prompt
$ftp_cmd
bye
!
试过了不行,在说了日期$path 和 $(date +%Y%m03) 应该都不是string吧!