在ubuntu的bash中循环执行脚本,并在内存不足时重启

#!/bin/bash
date
ma=`grep MemAvailable /proc/meminfo | awk '{print $2}'`
echo MemAvailable = $ma

runningloop=0

while true
do

  ((runningloop=runningloop+1))

  termname="darknet-running-${runningloop}"

  gnome-terminal -t $termname -- bash -c "bash ./darknet.sh"

  ma=`grep MemAvailable /proc/meminfo | awk '{print $2}'`
  ((ma=ma/1000))
  echo MemAvailable = $ma MB

  while [ $ma -gt 2000 ]
  do
    date
    ma=`grep MemAvailable /proc/meminfo | awk '{print $2}'`
    ((ma=ma/1000))
    echo MemAvailable = $ma MB
    sleep 1s
  done
  

  pkill darknet
  sleep 5s

done

 

posted @ 2019-04-29 15:18  aimhabo  阅读(706)  评论(0编辑  收藏  举报