如果你是一个软件开发人员,如果你是一个经常做产品上线操作的程序员,你一定会对tar命令很熟悉,它是一个打包命令,但具体的打包内容可能是一个很长的文件列表,如果部分文件上线的话人工制作一个文件列表是一件很浪费精力的事情。
于是我写了一个shell脚本,用来查找自上一次上线后更新的文件,只需要输入上次上线的前一天,即可自动生成一个文件列表,程序代码如下:
#!/bin/sh
FILE_HOME="/app/gau/www";
>/app/gau/wesley/uid.tmp;
awk 'BEGIN{
printf "Do you confirm this is the FILE_HOME:{'"$FILE_HOME"'}?"
getline result > "/dev/tty" ;
while( result != "yes" )
{
printf "please reset the FILE_HOME in this shell script.../n"
uid="`id -u`"
system("ps -u '"$uid"' -f | grep '"get_latest_files"' | egrep -v '"awk"' | egrep -v '"vi"' | egrep -v '"grep"' > /app/gau/wesley/uid.tmp")
exit;
}
}';
cnt=`cat /app/gau/wesley/uid.tmp | wc -l`
while [ $cnt -gt 0 ] ; do
line=`sed -n "${cnt}p" /app/gau/wesley/uid.tmp`
pid=`echo $line| cut -d " " -f2`
kill -9 $pid
echo stop $pid
cnt=`expr $cnt-1`
done
echo "please input the last date of the tag_date,date format is like 2010-03-01...";
eval $( awk '{
getline date1 > "/dev/tty" ;
printf "date1="date1;
exit;
}';
);
echo "find the files modified before $date1";
find $FILE_HOME -type f -ctime -$(echo " ( $(date +%s) - $(date +%s -d $date1)) / ( 3600 * 24 ) " | bc) > /app/gau/wesley/file_list.log;
sed 's///app//gau /g' /app/gau/wesley/file_list.log > /app/gau/wesley/file_list_tmp.log;
sed '/www//gau//WEB-INF//classes/d' /app/gau/wesley/file_list_tmp.log > /app/gau/wesley/file_list_tmp1.log;
sed '/www//gau//MerKey/d' /app/gau/wesley/file_list_tmp1.log > /app/gau/wesley/file_list.log;
rm /app/gau/wesley/file_list_tmp.log;
rm /app/gau/wesley/file_list_tmp1.log;
代码比较粗糙,如果有不明白或有新的建议请联系我; E-Mail: wesleyzhong007@gmail.com