flycat

Some if-then-else-case examples

Oct 6th, 2011 (edited)
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.08 KB | None | 0 0
  1. # If process not exist
  2. if [ `ps ax|grep squid|grep -v grep|wc -l` = 0 ]; then
  3.     echo "Squid is down. Starting"
  4.     /usr/local/squid/sbin/squid
  5. fi
  6. #-=-=-=-=-=-=-=-=-
  7. if [ ! `pgrep -f "memcached.*128" >/dev/null` ];then /usr/sbin/memcached; fi
  8. #-=-=-=-=-=-=-=-=-
  9. pgrep -f "memcached.*128" >/dev/null || /usr/sbin/memcached
  10.  
  11. # If file exist
  12. zpid=/var/tmp/zabbix_agentd.аpid
  13. if [ -f $zpid ]; then
  14.     rm -f $zpid
  15. fi
  16.  
  17. # If variable is empty:
  18. if [ -z ${HOSTS} ]
  19. # If variable found:
  20. if [[ "${PREPARING_COMMAND}" ]]
  21.  
  22. # If 1 OR 2
  23. if [ -z ${HOSTS[$i]#*:} ] || [ ${HOSTS[$i]#*:} == "ALL" ]
  24. # If 1 AND 2
  25. if (( $time >= 8 )) && (( $time <= 12 ))
  26.  
  27. # If substring found
  28. msg="test test PROBLEM asd asd"
  29. if [[ "$msg" == *PROBLEM* ]]
  30. then
  31.        echo bla
  32. fi
  33.  
  34.  
  35. # Case
  36. case "$1" in
  37.   start)
  38.         echo "Starting"
  39.         ;;
  40.   stop)
  41.         echo "Stopping"
  42.         ;;
  43.   reload)
  44.         ;;
  45.   restart|force-reload)
  46.         echo "Restarting"
  47.         ;;
  48.   *)
  49.         echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}" >&2
  50.         ;;
  51. esac
Advertisement
Add Comment
Please, Sign In to add comment