1 这个脚本实现了从ftp 服务器上批量下载文档。用mget 实现了批量下载。
#!/bin/bash
#desc:download the ftp files && filtered repeated files#desc:download the ftp files
u=username
p=password
ip=ip address
#T=`date +%Y%m%d`
T=`date -d '1 day' +%Y%m%d` ##明天的日期
#T=`date -d 'last day' +%Y%m%d` ##昨天的日期
echo "The date is:"
echo $T
rm -rf /root/filefolder/*.txt
rm -rf /root/filefolder/filefolder_utf8/*.txt
ftp -n <<EOF
open $ip
user $u $p
binary
cd /bak
lcd /root/filefolder
prompt
mget *_$T.*.txt
close
bye
EOF
echo "The file download successful!"
2 shell 实现改变txt 文档的编码方式,以gb2132 ->utf8 为例。
#!/bin/bash
#格式:./gb2312_2_utf8.sh param1 param2
IFSBACKUP=$IFS #备份IFS变量
IFS=$(echo -en "\n\b") #设置IFS变量不含空格,防止文件名中有空格时出现异常
dst=$(echo $1|sed 's/\/$//') #如果路径末尾有“/”,删除掉,后面再添加
dstutf8=$(echo $2|sed 's/\/$//')
for file in $(ls "$dst"|grep .txt)
do
gb2312file=$dst\/$file
utf8file1=${dstutf8}\/$file
#echo ${utf8file1}
utf8file=$(echo "${utf8file1}"|sed 's/.txt$/-utf8.txt/')
string=$(file "$gb2312file"|grep Unicode) #简单判断文件是否为Unicode文件,如果是,则不转换
if [ "$string" = "" ]
then
iconv -f GB18030 -t utf-8 "$gb2312file" > "$utf8file"
else
echo "$gb2312file" is Unicode text file
fi
done
IFS=$IFSBACKUP
exit 0
echo "The file transfer successful!"
这个是工作备忘,应该是参考了其他人的博客写好的,但是具体文章我忘记了,如果您看见了,请联系我,我重新注明出处。