原帖由 "liuxuexin_xxlhz" 发表:
#!/bin/sh
# ftpget.sh
SPSC_SERVER=192.168.0.1
FTP_USERNAME=11
FTP_PASSWORD=11
FILE_PRENAME=mobile
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/gateway
else
exec>>/chroot/gateway/log/recv`date '+%Y%m%d'`.log 2>&1
if [ "-d" = "$1" ]
then DEST_PATH=$2
else DEST_PATH=/chroot/gateway/
fi
cd $DEST_PATH
Log "Begin to get filelist..."
# You can NOT use mget and mdelete commands of ftp to handle this issue,
# because when you begin to execute the mdelete command,
# it's possible that a new file have been written into the disk,
# just before the mdelete command start and after mget command had been finished.
# as a result, firstly, you should get the file list,
# secondly, get and delete each file in the list
# Step 1: Get the file list from FTP server
ftp -i -n $SPSC_SERVER <<MACRO_END1
user $FTP_USERNAME $FTP_PASSWORD
bin
原帖由 "liuxuexin_xxlhz" 发表:
bye
MACRO_END1
if [ ! -s filelist ];then
Log "No file received......"
rm -f filelist
exit
fi
原帖由 "liuxuexin_xxlhz" 发表:
# # Step 2: Get and delete each file in circle.
# "cut -b56-" means get the filename from 56th bytes in each line in filelist file,
# you can adjust the number by yourself after read the filelist file.
# In our testing environment of Turbo Linux and Red Hat Linux, the number is set to 56
# In our testing environment of Solaris and AIX, the number is set to 1
Log "transfering start..."
for _FILENAME in `more filelist|cut -b56-` ; do
ftp -i -n $SPSC_SERVER <<MACRO_END2
user $FTP_USERNAME $FTP_PASSWORD
bin
get $_FILENAME $_FILENAME.tmp
原帖由 "liuxuexin_xxlhz" 发表:
bye
MACRO_END2
mv $_FILENAME.tmp $_FILENAME
Log "get $_FILENAME ok"
gunzip $_FILENAME
Log "gunzip $_FILENAME ok"
. /chroot/gateway/bin/subsync.sh
done
rm -f filelist
Log "transfering completed."
原帖由 "liuxuexin_xxlhz" 发表:
# Step 3: Handle files based on your business logic
# The following handle program should be written by yourself !!!
#for _FILENAME in `more filelist|cut -b56-` ; do
# java HandleUnsubRecord ......
#done
fi
使用comm的前提是,两个文件必须是经过排序过的
基本格式:
comm -1|-2|-3 file1 file2
-1:不显示在file1中存在的行
-2:不显示在file2中存在的行
-3:不显示在file1和file2中都存在的行
例如不显示file1,file2都有的行
comm -3 file1 file2
mv filelist.$$.txt filelist.txt
diff filelist.$$.txt filelist.txt |grep "<" |awk '{print $2}' >file to get
-rw-rw-rw-
-rw-rw-rw-
-rw-rw-rw-
-rw-rw-rw-
1
1
1
1
在使用 positional parameter 的時候,我們要注意一些陷阱哦:
* $10 不是替換第 10 個參數,而是替換第一個參數($1)然後再補一個 0 於其後﹗
也就是,my.sh one two three four five six seven eigth nine ten 這樣的 command line ,
my.sh 裡的 $10 不是 ten 而是 one0 哦... 小心小心﹗
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |