带校验部署二进制文件

bash下载一些二进制软件直接运行的时候,最好验证一下,避免存在网络劫持存在安全隐患,避免下载出错运行出现一些问题。

#!/bin/bash
#一个例子
softbin='bcachequick'
path='/usr/local/bin'
bcachequick_downurl='http://....'#避免证书失败最好整http
bcachequick_md5='8b3b78200f47f3d746443c780aa43bca'


downfile(){
	wget $bcachequick_downurl -O $path/$softbin
  testfile
}
testfile(){
	localmd5=$(md5sum $path/$softbin | awk '{print $1}' )
	["$localmd5" == "bcachequick_md5"] || {
		rm -f $path/$softbin
  	downfile
  	
	}
}
downfile
testfile

yum真的装完了?

有的时候因为一些情况没装完。最好处理下。

install_example(){
	example -V && return 
	yum install example -y || {
	#其他的告警
  exit 1
  }
}

避免频繁运行

限制一定间隔内不能重复执行,类似防止重复运行

pid=/tmp/rsync_mirrors.pid
[ -f $pid ] && {
	pidtime=$(ls -g --time-style=+%s $pid | awk '{print $5}')
	this_time=$(date +%s)
  #比如说时间不过半
  [ $((this_time - pidtime)) -lt 900 ] && touch $pid && exit 1
	#如果已经过半
  [ $((this_time - pidtime)) -lt 1800 ] && exit 2
}
rm -f $pid
#rsync....