function check_ip() { local ip=$1 info "Check ip: $ip" local valid_check=$(echo $ip | awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}') if echo $ip | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$">/dev/null; then if [ ${valid_check:-no} == "yes" ]; then echo "IP $ip available." else error "IP $ip not available!" return 311 fi else error "IP format error!" return 312 fi }
if条件中使用正则表达式
The =~ Regular Expression match operator no longer requires quoting of the pattern within [[ … ]].
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13
newip="192.168.1.1" if [[ "$newip" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo "找到了ip地址" fi #or
if [[ "$tag_version" =~ ^v[0-9].[0-9].[0-9] ]]; then echo "$tag_version format is valid." else echo "$tag_version format error. example: v0.0.1 or v0.0.1a" exit 1 fi
sed -i "/^BOOTPROTO/c BOOTPROTO=static" /etc/sysconfig/network-scripts/ifcfg-eno1 sed -i "/^ONBOOT/c ONBOOT=yes" /etc/sysconfig/network-scripts/ifcfg-eno1 sed -i "/^IPADDR/c IPADDR=192.168.1.11" /etc/sysconfig/network-scripts/ifcfg-eno1 sed -i '$a NETMASK=255.255.255.0' /etc/sysconfig/network-scripts/ifcfg-eno1
配置IP地址
递归便利整个目录及子目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
function getdir(){ echo $1 for file in $1/* do if test -f $file then echo $file arr=(${arr[*]} $file) else getdir $file fi done } getdir ./src #echo${arr[@]}
while read LINE do if echo $LINE|grep 'cpu_tmp' then cpu_tmp=${LINE#*:} fi
if echo $LINE|grep 'cycles' then cycles=${LINE#*:} fi
done < run.cfg #多线程: # init fifo file THREAD1DIR=3 && FIFONR=4 && FIFONAME="$$.ff" && mkfifo $FIFONAME && str="exec $FIFONR<> $FIFONAME" && eval $str && rm $FIFONAME -f i=0 while [ $i -lt $THREAD1DIR ]; do i=$((i+1)) echo done >& $FIFONR #for (( i=0; i<$THREAD1DIR; i++ )); do # start test 1st level dir all=`find . -maxdepth 1 -name "?????\.*"` for i in $all do if [ -d $i ] then read ( echo $i" 1runing" && cd $i/ && ./$i'.run'.sh $cycles && cd - && echo >& $FIFONR ) & fi done <& $FIFONR # rm fifo file wait && str="exec $FIFONR>&-" && eval $str #get log [ -d $data_dir ] && rm -rf $data_dir || mkdir $data_dir && cp run.cfg $data_dir -f
for i in $all do if [ -d $i ] then des_dir=$data_dir'/'$i'/' mkdir $des_dir src_dir='./'$i'/' file_path=`find $src_dir/ -name *_*.log` echo $file_path mv $file_path $des_dir fi done chmod 777 './'$data_dir -R rm *.ff -f
修改文件名后缀
1 2 3 4 5 6
for file in `find . -name "*.f90"` do newfile=${file%.*}.f77 #echo"$newfile" mv $file $newfile done