Browse Source

first commit

Nicolo' Palazzini 5 years ago
parent
commit
d478ed9fc0
2 changed files with 20 additions and 25 deletions
  1. 13 11
      functions
  2. 7 14
      sleepctl

+ 13 - 11
functions

@@ -2,7 +2,6 @@ print_usage(){
 	echo
 	echo "script usage: $(basename $0) [-s node] [-k node] [-m] [-h] " >&2
 	echo "type: '$(basename $0) -h' for help"
-	return 0
 }
 
 print_help(){
@@ -16,17 +15,18 @@ print_help(){
 	echo "  -h  Print this help message"
 	command_parsed=1
 
-
 	return 0
 }
 
 start_node(){
 	
-	ssh $1 'sleep 300 &> /dev/null &' #come si fa a non mostrare il messaggio?
+	ssh $1 'sleep 300 &> /dev/null &' #da sostituire con il comando per xfreerdp
 	echo "Service started on $1"
+
+	#aggiungere la gestione di un nome errato
 		
 	command_parsed=1
-
+	return 0
 }
 
 start_1(){
@@ -34,7 +34,7 @@ start_1(){
 		do
   	 		start_node ${LCM1[i]}
 		done
-	command_parsed=1
+	return 0
 }
 
 start_2(){
@@ -42,11 +42,11 @@ start_2(){
 		do
 			start_node ${LCM2[i]}
 		done
-	command_parsed=1	
+	return 0	
 }
 
 monitor(){
-
+	#da migliorare: lentissima!
 	echo "Service running on:"
 	for i in {0..12}
 		do
@@ -65,15 +65,17 @@ monitor(){
 		done
 
 	command_parsed=1
-
+	return 0
 }
 
 kill_process(){
 	
 	ssh $1 'pkill sleep' #pericoloso (testato e funzionante con pkill xfreerdp)
 
-	command_parsed=1
+	#aggiungere la gestione di un nome errato
 
+	command_parsed=1
+	return 0
 }
 
 kill_1(){
@@ -81,7 +83,7 @@ kill_1(){
 		do
 			kill_process ${LCM1[i]}
 		done
-
+	return 0
 }
 
 kill_2(){
@@ -89,5 +91,5 @@ kill_2(){
 		do
 			kill_process ${LCM2[i]}
 		done
-
+	return 0
 }

+ 7 - 14
sleepctl

@@ -1,8 +1,8 @@
 #!/bin/bash
 
-#set -e #problemi con la funzione monitor! DOCUMENTARSI!!!!!
-set -u
-set -o pipefail
+#set -e #(errexit) esce quando un comando ritorna un valore diverso da zero (non va bene per come è implementata la funzione monitor)
+set -u #tratta le variabili non definite come errori
+set -o pipefail #ritorna zero se tutto è andato a buon fine (di default guarda solo l'ultimo comando)
 
 command_parsed=0
 
@@ -11,11 +11,10 @@ command_parsed=0
 
 while getopts 'hms:k:' OPTION; do
   case "$OPTION" in
-
-    m) #monitor
+	m) #funzione monitor
 		monitor
 		;;
-	s) #start
+	s) #funzione start
 		node=$OPTARG
 		if [ $node == '1' ];then
   			start_1
@@ -25,7 +24,7 @@ while getopts 'hms:k:' OPTION; do
   		 	start_node $node
 		fi
 		;;
-	k)  #kill
+	k)  #funzione kill
 		node=$OPTARG
 		if [ $node == '1' ];then
   			kill_1
@@ -38,14 +37,10 @@ while getopts 'hms:k:' OPTION; do
 	h)
 		print_help      
 		;;
-    ?)
+	?)
 		print_usage
 		exit 1
- 		command_parsed=1
 	    ;;
-    :)
-      	echo "cosa fa?"
-      	;;
   esac
 done
 
@@ -53,5 +48,3 @@ if [ $command_parsed -eq 0 ]
 then
     print_usage
 fi
-
-#shift "$(($OPTIND -1))"