Advertisement
alexs77

zimbra-control.sh

Aug 26th, 2016
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.02 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. start () {
  4.     echo "Starte Zimbra $1 Umgebung..."
  5.     for h in zcs-ds7-$1; do
  6.         if ping -c1 $h > /dev/null 2>&1; then
  7.             echo "$h"
  8.             ssh -l zimbra "$h" "zmcontrol start"
  9.             echo
  10.         else
  11.             echo "$h nicht erreichbar?!?"
  12.         fi
  13.     done
  14.  
  15.     for h in zcs-ds6-$1; do
  16.         if ping -c1 $h > /dev/null 2>&1; then
  17.             echo "$h"
  18.             ssh -l zimbra "$h" "zmcontrol start"
  19.             echo
  20.         else
  21.             echo "$h nicht erreichbar?!?"
  22.         fi
  23.     done
  24.  
  25.     for h in zcs-{{b,f}e{5,6},ff3}-$1; do
  26.         if ping -c1 $h > /dev/null 2>&1; then
  27.             echo "$h"
  28.             ssh -l zimbra "$h" "zmcontrol start" &
  29.             echo
  30.         else
  31.             echo "$h nicht erreichbar?!?"
  32.         fi
  33.     done; wait
  34.     echo "...ageschlossen"
  35. }
  36.  
  37. stop () {
  38.     echo "Stoppe Zimbra $1 Umgebung..."
  39.     for h in zcs-{{b,f}e{5,6},ff3,ds6}-$1; do
  40.         if ping -c1 $h > /dev/null 2>&1; then
  41.             echo "$h"
  42.             ssh -l zimbra "$h" "zmcontrol stop" &
  43.             echo
  44.         else
  45.             echo "$h nicht erreichbar?!?"
  46.         fi
  47.     done; wait
  48.  
  49.     for h in zcs-ds7-$1; do
  50.         if ping -c1 $h > /dev/null 2>&1; then
  51.             echo "$h"
  52.             ssh -l zimbra "$h" "zmcontrol stop"
  53.             echo
  54.         else
  55.             echo "$h nicht erreichbar?!?"
  56.         fi
  57.     done
  58.     echo "...abgeschlossen"
  59. }
  60.  
  61. restart () {
  62.     echo "Restart Zimbra $1 Umgebung"
  63.     for h in zcs-ds7-$1; do
  64.             if ping -c1 $h > /dev/null 2>&1; then
  65.             echo "$h"
  66.             ssh -l zimbra "$h" "zmcontrol stop; zmcontrol start"
  67.             echo
  68.         else
  69.             echo "$h nicht erreichbar?!?"
  70.         fi
  71.     done
  72.  
  73.     for h in zcs-{ds6,{b,f}e{5,6},ff3}-$1; do
  74.         if ping -c1 $h > /dev/null 2>&1; then
  75.             echo "$h"
  76.             ssh -l zimbra "$h" "zmcontrol stop; zmcontrol start" &
  77.             echo
  78.         else
  79.             echo "$h nicht erreichbar?!?"
  80.         fi
  81.     done; wait
  82.     echo "...abgeschlossen"
  83. }
  84.  
  85. status () {
  86.     echo "Status der Zimbra $1 Umgebung..."
  87.     for h in zcs-{ds{7,6},{b,f}e{5,6},ff3}-$1; do
  88.         if ping -c1 $h > /dev/null 2>&1; then
  89.             echo "$h"
  90.             ssh -l zimbra "$h" "zmcontrol status"
  91.             echo
  92.         else
  93.             echo "$h nicht erreichbar?!?"
  94.         fi
  95.     done
  96.     echo "...abgeschlossen"
  97. }
  98.  
  99. setze_datum () {
  100.     echo "Setze Datum der Zimbra $1 Umgebung auf $(date)..."
  101.     for h in zcs-{ds{7,6},{b,f}e{5,6},ff3}-$1; do
  102.         if ping -c1 $h > /dev/null 2>&1; then
  103.             echo "$h"
  104.             ssh -l root "$h" "printf 'Uhrzeit (alt): '; date; date --set=@$(date +%s); printf 'Uhrzeit (neu): '; date"
  105.             echo
  106.         else
  107.             echo "$h nicht erreichbar?!?"
  108.         fi
  109.     done
  110.     echo "...abgeschlossen"
  111. }
  112.  
  113. lese_datum () {
  114.     echo "Hole Datum der Zimbra $1..."
  115.     for h in zcs-{ds{7,6},{b,f}e{5,6},ff3}-$1; do
  116.         if ping -c1 $h > /dev/null 2>&1; then
  117.             echo "$h"
  118.             ssh -l zimbra "$h" "printf 'Uhrzeit: '; date"
  119.             echo
  120.         else
  121.             echo "$h nicht erreichbar?!?"
  122.         fi
  123.     done
  124.     echo "...abgeschlossen"
  125. }
  126.  
  127. reboot () {
  128.     echo "Reboote alle Systeme der Zimbra $1 Umgebung..."
  129.     printf "Wirklich? [j/n] "; read
  130.     [[ "$REPLY" != "j" ]] && return
  131.     for h in zcs-{ds{7,6},{b,f}e{5,6},ff3}-$1; do
  132.         if ping -c1 $h > /dev/null 2>&1; then
  133.             echo "$h"
  134.             ssh -l root "$h" "reboot &" &
  135.             echo
  136.         else
  137.             echo "$h nicht erreichbar?!?"
  138.         fi
  139.     done
  140.     echo "...abgeschlossen"
  141. }
  142.  
  143. aufruf () {
  144.     echo "Aufruf: $0 [-1|-0|-s|-r] [-P] [-R]"
  145.     echo ""
  146.     echo " -1: Starte die Zimba Test Umgebung"
  147.     echo " -0: Stoppe die Zimbra Test Umgebung"
  148.     echo " -s: Status der Zimbra Test Umgebung"
  149.     echo " -r: Restart der Zimbra Test Umgebung"
  150.     echo " -d: Datum der VMs der Zimbbra Test umgebung auslesen"
  151.     echo " -D: Datum der VMs auf Datum der akt. Workstation setzen"
  152.     echo " -B: Reboot der Zimbra Test Umgebung"
  153.     echo " -P: Verwende Zimbra PROD Umgebung, anstelle von Test"
  154.     echo " -R: Verwende Zimbra PROD-Restored Umgebung, anstelle von Test"
  155. }
  156.  
  157. action="unbekannt"
  158. systems="test"
  159. while getopts "10srdDBPR" options; do
  160.     case $options in
  161.         1)
  162.             action="start"
  163.             ;;
  164.         0)
  165.             action="stop"
  166.             ;;
  167.         s)
  168.             action="status"
  169.             ;;
  170.         r)
  171.             action="restart"
  172.             ;;
  173.         d)
  174.             action="lese_datum"
  175.             ;;
  176.         D)
  177.             action="setze_datum"
  178.             ;;
  179.         B)
  180.             action="reboot"
  181.             ;;
  182.         P)
  183.             systems="prod"
  184.             ;;
  185.         R)
  186.             systems="prod-restored"
  187.             ;;
  188.         \?)
  189.             aufruf
  190.             exit 1
  191.             ;;
  192.     esac
  193. done
  194.  
  195. if [ "unbekannt" = "$action" ]; then aufruf; exit 1; fi
  196.  
  197. "$action" "$systems"
  198. exit 0
  199. # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement