当前目录下两个rpm包做差分。
*.rpm
两个目录,解压rpm包。
export LANG=c
差分判断是脚本还是Binary Files
脚本添加命令行提示符,awk。
[root@sj_x861 diff_rwz]# cat diff_rpm.sh
#!/bin/bash
export LANG=c
source ~/.bashrc
#############################
#basic command label
#############################
if [ "$(whoami)" = "$(basename $(pwd))" ]; then
cmd_label="[$(whoami)@$(hostname) ~]# "
else
cmd_label="[$(whoami)@$(hostname) $(basename $(pwd))]# "
fi
mkdir new_bin/ new_rpm/ old_bin/ old_rpm/
rpms=(`ls *.rpm`)
cp -a ${rpms[0]} old_rpm
cp -a ${rpms[1]} new_rpm
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}ls -l */*.rpm"
ls -l */*.rpm
echo -e "${cmd_label}md5sum */*.rpm"
md5sum */*.rpm
echo -e "${cmd_label}cd new_bin/"
cd new_bin/
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}rpm2cpio ../new_rpm/*.rpm | cpio -idm"
rpm2cpio ../new_rpm/*.rpm | cpio -idm
echo -e "${cmd_label}cd ../old_bin/"
cd ../old_bin/
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}rpm2cpio ../old_rpm/*.rpm | cpio -idm"
rpm2cpio ../old_rpm/*.rpm | cpio -idm
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}cd .."
cd ..
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}diff -r old_bin/ new_bin/"
diff -r old_bin/ new_bin/
diff -r old_bin/ new_bin/ | grep "Binary files " >/var/tmp/diff_rpm.txt
if [[ -s /var/tmp/diff_rpm.txt ]];then
echo -e "${cmd_label}diff -r old_bin/ new_bin/ | grep "Binary files " | awk '{print $3; print $5}' | xargs md5sum"
diff -r old_bin/ new_bin/ | grep "Binary files " | awk '{print $3; print $5}' | xargs md5sum
fi
diff -r old_bin/ new_bin/ | grep "diff -r " >/var/tmp/diff_rpm.txt
if [[ -s /var/tmp/diff_rpm.txt ]];then
echo -e "${cmd_label}diff -r old_bin/ new_bin/ | grep "diff -r " | awk '{print $3; print $4}' | xargs md5sum"
diff -r old_bin/ new_bin/ | grep "diff -r " | awk '{print $3; print $4}' | xargs md5sum
fi
rm -rf new_bin/ new_rpm/ old_bin/ old_rpm/
[root@sj_x861 diff_rwz]# cat
awk
[root@sj_x861 diff_rms]# cat temp
ls
ll */*.rpm
md5sum */*.rpm
cd new_bin/
ls
rpm2cpio ../new_rpm/*.rpm | cpio -idm
cd ../old_bin/
ls
rpm2cpio ../old_rpm/*.rpm | cpio -idm
ls
cd ..
ls
diff -r old_bin/ new_bin/
diff -r old_bin/ new_bin/ | grep "Binary files " | awk '{print $3; print $5}' | xargs md5sum =>双引号和美元符号需要转义.
#diff -r old_bin/ new_bin/ | grep "diff -r " | awk '{print $3; print $4}' | xargs md5sum
[root@sj_x861 diff_rms]# cat temp | awk '{ print "echo -e "${cmd_label}"$0"""; print $0}'
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}ll */*.rpm"
ll */*.rpm
echo -e "${cmd_label}md5sum */*.rpm"
md5sum */*.rpm
echo -e "${cmd_label}cd new_bin/"
cd new_bin/
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}rpm2cpio ../new_rpm/*.rpm | cpio -idm"
rpm2cpio ../new_rpm/*.rpm | cpio -idm
echo -e "${cmd_label}cd ../old_bin/"
cd ../old_bin/
echo -e "${cmd_label}ls"
ls
echo -e "${cmd_label}rpm2cpio ../old_rpm/*.rpm | cpio -idm"
rpm2cpio ../old_rpm/*.rpm | cpio -idm
end