- 论坛徽章:
- 0
|
一个很不错的ftp脚本,但是我不会改哦
不好意思,是我自己弄错了,你的说法就是正确的。不过在我的程序中有一个cut56这个参数,导致我从服务器上get不下来东东。我把整个修改好的文件贴上来,大家参考!- #!/bin/sh
- # ftpget.sh
- SPSC_SERVER=192.168.0.1
- FTP_USERNAME=11
- FTP_PASSWORD=11
- FILE_PRENAME=11
- Log ()
- {
- echo [`date '+%Y%m%d %H:%M:%S'` $$] $*
- }
- if [ "-?" = "$1" ]
- then echo usage: ftpgetsample.sh [-d dest_path]
- echo dest_path: The local path in which files are stored, the recv path is default.
- echo A sample: ftpget.sh -d /chroot
- else
- exec>>/chroot/log/recv`date '+%Y%m%d'`.log 2>&1
- if [ "-d" = "$1" ]
- then DEST_PATH=$2
- else DEST_PATH=/chroot
- fi
- cd $DEST_PATH
- Log "Begin to get filelist..."
-
- # Step 1: Get the file list from FTP server
- ftp -i -n $SPSC_SERVER <<MACRO_END1
- user $FTP_USERNAME $FTP_PASSWORD
- bin
- ls *$FILE_PRENAME.* filelist.$$.txt
- bye
- MACRO_END1
-
- awk '{print $ 9}' filelist.$$.txt >filelist.name.txt
- diff filelist.name.txt filelist.txt |grep "<" |awk '{print $2}' > filetoget
-
- if [ ! -s filetoget ];then
- Log "No file received......"
- rm -f filelist.$$.txt
- rm -f filelist.name.txt
- rm -f filetoget
- exit
- fi
- # Step 2: Get and delete each file in circle.
- Log "transfering start..."
- for _FILENAME in `cat filetoget` ; do
- ftp -i -n $SPSC_SERVER <<MACRO_END2
- user $FTP_USERNAME $FTP_PASSWORD
- bin
- get $_FILENAME $_FILENAME.tmp
- #delete $_FILENAME
- bye
- MACRO_END2
- mv $_FILENAME.tmp $_FILENAME
- Log "get $_FILENAME ok"
- gunzip $_FILENAME
- Log "gunzip $_FILENAME ok"
- done
-
- log "transfering completed."
- cat filetoget >> filelist.txt
- rm -f filelist.name.txt
- rm -f filetoget
- rm -f filelist.$$.txt
-
- fi
复制代码
当然了,这里还有几个问题不理解的
- if [ ! -s filetoget ];then
- Log "No file received......"
- rm -f filelist.$$.txt
- rm -f filelist.name.txt
- rm -f filetoget
- exit
- fi
复制代码
这里的 -s filetoget,参数-s是什么意思呢?
还有- for _FILENAME in `cat filetoget` ; do
- ftp -i -n $SPSC_SERVER <<MACRO_END2
- user $FTP_USERNAME $FTP_PASSWORD
- bin
- get $_FILENAME $_FILENAME.tmp
- #delete $_FILENAME
- bye
- MACRO_END2
复制代码 中的MACRO_END2是干吗用的?? |
|