functions 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. print_usage(){
  2. echo
  3. echo "script usage: $(basename $0) [-s node] [-k node] [-m] [-h] " >&2
  4. echo "type: '$(basename $0) -h' for help"
  5. }
  6. print_help(){
  7. echo
  8. echo "$(basename $0): a useless script"
  9. echo
  10. echo "options:"
  11. echo " -s <node> Start the service on the specified node"
  12. echo " -k <node> Kill the service on the specified node"
  13. echo " -m Monitor function: display all the nodes on which the service is runnig"
  14. echo " -h Print this help message"
  15. command_parsed=1
  16. return 0
  17. }
  18. start_node(){
  19. ssh $1 'sleep 300 &> /dev/null &' #da sostituire con il comando per xfreerdp
  20. echo "Service started on $1"
  21. #aggiungere la gestione di un nome errato
  22. command_parsed=1
  23. return 0
  24. }
  25. start_1(){
  26. for i in {0..12}
  27. do
  28. start_node ${LCM1[i]}
  29. done
  30. return 0
  31. }
  32. start_2(){
  33. for i in {0..14}
  34. do
  35. start_node ${LCM2[i]}
  36. done
  37. return 0
  38. }
  39. monitor(){
  40. #da migliorare: lentissima!
  41. echo "Service running on:"
  42. for i in {0..12}
  43. do
  44. #printf "${LCM1[i]}: "
  45. ssh ${LCM1[i]} 'ps aux | grep "sleep 300" | grep -v grep' > /dev/null
  46. if [ $? -eq 0 ]; then
  47. echo ${LCM1[i]}
  48. fi
  49. done
  50. for i in {0..14}
  51. do
  52. ssh ${LCM2[i]} 'ps aux | grep "sleep 300" | grep -v grep' > /dev/null
  53. if [ $? -eq 0 ]; then
  54. echo ${LCM1[i]}
  55. fi
  56. done
  57. command_parsed=1
  58. return 0
  59. }
  60. kill_process(){
  61. ssh $1 'pkill sleep' #pericoloso (testato e funzionante con pkill xfreerdp)
  62. #aggiungere la gestione di un nome errato
  63. command_parsed=1
  64. return 0
  65. }
  66. kill_1(){
  67. for i in {0..12}
  68. do
  69. kill_process ${LCM1[i]}
  70. done
  71. return 0
  72. }
  73. kill_2(){
  74. for i in {0..14}
  75. do
  76. kill_process ${LCM2[i]}
  77. done
  78. return 0
  79. }