You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mailrun.sh 587B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. # Check every ten seconds if the process identified as $1 is still
  3. # running. After 5 checks (~60 seconds), kill it. Return non-zero to
  4. # indicate something was killed.
  5. monitor() {
  6. local pid=$1 i=0
  7. while ps $pid &>/dev/null; do
  8. if (( i++ > 5 )); then
  9. echo "Max checks reached. Sending SIGKILL to ${pid}..." >&2
  10. kill -9 $pid; return 1
  11. fi
  12. sleep 10
  13. done
  14. return 0
  15. }
  16. read -r pid < ~/.offlineimap/pid
  17. if ps $pid &>/dev/null; then
  18. echo "Process $pid already running. Exiting..." >&2
  19. exit 1
  20. fi
  21. offlineimap -o -u quiet & monitor $!