SHELL四则运算和比较

  #http://www.jb51.net/article/bin/bash

  #获取英文月份对应的数字月份

  getmonthofenglish()

  {

  case "$1" in

  "Jan") msg_month=1;;

  "Feb") msg_month=2;;

  "Mar") msg_month=3;;

  "Apr") msg_month=4;;

  "May") msg_month=5;;

  "Jun") msg_month=6;;

  "Jul") msg_month=7;;

  "Aug") msg_month=8;;

  "Sept") msg_month=9;;

  "Oct") msg_month=10;;

  "Nov") msg_month=11;;

  "Dec") msg_month=12;;

  esac

  }

  # 判断是否有过期短信,有调用C删除短信函数

  del_overtime_sms()

  {

  num=`ipcs -q|grep "$1"|awk '{print $6}'`

  if (( "$num" > "1" )); then

  ipcs -q|grep "$1"|awk '{print $2,$6}'>overtimesms.ini

  http://www.jb51.net/article/del_overtime_sms //shell中调用C函数的结果

  else

  echo "消息队列中没有过期的短信"

  fi

  }

  #获取当前月份对应的天数

  cd /mas/shell/zhangweiatest/clear_overtime_sms

  mday=`http://www.jb51.net/article/getmonthofday`

  echo "当前月份前一个月对应的天数=$mday"

  #获取系统时间对应的年,月

  buff=`date|awk '{print $2,$3}'`

  now_month=${buff:0:1}

  now_day=${buff:3:1}

  #获取当前队列的存活时间

  ipcs -qt|awk '{print $1,$3,$4}'>msglivelytime.ini

  sed -n '4,$p' msglivelytime.ini >msglivelytime1.ini //获取从第四行开始到结束的字符

  mv msglivelytime1.ini msglivelytime.ini

  while read msgid msg_month msg_day

  do

  echo

  echo "消息队列ID=$msgid创建的时间为:$msg_month月$msg_day日"

  echo "系统时间为$now_month月的第$now_day天"

  getmonthofenglish "$msg_month"

  let "new_month = $msg_month + 1"

  if [ "$msg_month" = "Not" ]; then //为空NULL

  echo "队列安全"

  elif [ "$msg_month" = "" ]; then //空行

  echo "NULL"

  elif [ "$msg_month" = "$now_month" ]; then

  let "msg_day1 = $msg_day + 2"

  if (( "$now_day" >= "$msg_day1" )); then

  if (( "$msg_day" < "$mday" )); then

  echo "消息队列不安全"

  del_overtime_sms "$msgid"

  fi

  fi

  elif [ "$now_month" = "$new_month" ]; then

  let "now_day1 = $now_day + $mday"

  let "msg_day1 = $msg_day + 2"

  echo "now_day1=$now_day1,msg_day1=$msg_day1"

  if (( "$now_day1" >= "$msg_day1" )); then

  # if (( "$msg_day1" < "$mday" )); then

  echo "消息队列不安全"

  del_overtime_sms "$msgid"

  # fi

  fi

  elif (( "$now_month" > "$new_month" )); then

  echo ""$msg_month" > "$now_month""

  del_overtime_sms "$msgid"

  echo "消息队列不安全"

  else

  echo "msg queue safe"

  fi

  done < msglivelytime.ini