preflight 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. ################################################################################
  3. #
  4. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #################################################################################
  18. declare -a arr0
  19. declare -a arr1
  20. declare -a arr2
  21. declare -a arrPIDName
  22. declare -a arrPIDPath
  23. declare -a arrDep
  24. if [ "${1:0:1}" == '-' ]; then
  25. if [ $# -lt 2 ]; then
  26. echo usage: $0 -p=PIDPath[,PIDPath,...] -n=PIDName[,PIDName,...] [-m=YES/NO] [-d=dependency,dependency,...]
  27. exit 1
  28. fi
  29. dfOption='-l'
  30. depAll=0
  31. for (( i=1;$i<=$#;i=$i+1 )) do
  32. case ${!i:0:3} in '-p=')
  33. IFS=, read -a arrPIDPath <<< "${!i:3}";;
  34. '-n=')
  35. IFS=, read -a arrPIDName <<< "${!i:3}";;
  36. '-d=')
  37. if [ "${!i:3}" == 'ALL' ]; then
  38. depAll=1
  39. else
  40. IFS=, read -a arrDep <<< "${!i:3}"
  41. fi
  42. ;;
  43. '-m=')
  44. if [ "${!i:3}" == 'YES' ]; then
  45. dfOption='-a'
  46. fi
  47. ;;
  48. *)
  49. echo "wrong augument:${!i}";;
  50. esac
  51. done
  52. lPath=${#arrPIDPath[*]}
  53. if [ ${#arrPIDName[@]} -gt $lPath ]; then
  54. lastPath=${arrPIDPath[lPath-1]}
  55. for (( i = $lPath; i < ${#arrPIDName[@]}; i++)); do
  56. arrPIDPath[i]=$lastPath
  57. done
  58. fi
  59. #find machineInfo and output:
  60. mem=`free | head -n 3 | tail -n 1 | awk '{print $3,$4}'`
  61. cpu=`vmstat 1 2 | tail -n 1 | awk '{print $15}'`
  62. echo CPU-Idle: $cpu%
  63. cuptime=`uptime | cut -f 1,2 -d ','`
  64. echo ComputerUpTime: $cuptime
  65. echo ---SpaceUsedAndFree---
  66. swap=`free | tail -n 1 | awk '{print $3,$4}'`
  67. echo Physical Memory: $mem
  68. echo Swap: $swap
  69. i=0
  70. for name in `df $dfOption | tail -n +2 | awk '{if(NF>=4) print $NF}'`; do
  71. arr0[i]=$name
  72. i=$((i+1))
  73. done
  74. i=0
  75. for used in `df $dfOption | tail -n +2 | awk '{if(NF>=4) print $(NF-3)}'`; do
  76. arr1[i]=$used
  77. i=$((i+1))
  78. done
  79. i=0
  80. for free in `df $dfOption | tail -n +2 | awk '{if(NF>=4) print $(NF-2)}'`; do
  81. arr2[i]=$free
  82. i=$((i+1))
  83. done
  84. for j in $(seq 0 $((i-1))); do
  85. echo ${arr0[$j]}: ${arr1[$j]} ${arr2[$j]}
  86. done
  87. # foreach PIDName in arrPIDName do: find process info and output
  88. echo ---ProcessList1---
  89. i=0
  90. for (( i = 0; i < ${#arrPIDName[@]}; i++)); do
  91. full=${arrPIDPath[i]}/${arrPIDName[i]}.pid
  92. pid=`cat $full`
  93. elapsed=`ps -o etime $pid | sed -e '1d' | tail -n 1`
  94. echo Process ${arrPIDPath[i]}/${arrPIDName[i]}: $pid $elapsed
  95. done
  96. #read other processes
  97. echo ---ProcessList2---
  98. if [[ $depAll -gt 0 ]]; then
  99. ps -el | tail -n +1 | awk '{print $4,$14;}'
  100. else
  101. echo 'NAME:PID CMD'
  102. for (( i = 0; i < ${#arrDep[@]}; i++)); do
  103. aDep=${arrDep[i]}
  104. aDepInit=init_$aDep
  105. #depCHK=$(ps aux | grep $aDep | grep -v grep | grep -v $aDepInit | wc -l)
  106. depCHK=$(ps -el | grep $aDep | grep -v grep | grep -v $aDepInit | awk '{print $4,$14;}')
  107. echo $aDep:$depCHK
  108. done
  109. fi
  110. else
  111. i=0
  112. if [ $# -lt 2 ]; then
  113. echo usage: $0 dir command
  114. exit 1
  115. fi
  116. #full=$1/$2
  117. #pid=`ps -ef | grep $full | grep -v grep | awk '{print $2}'`
  118. full=$1/$2.pid
  119. pid=`cat $full`
  120. echo ProcessID: $pid
  121. elapsed=`ps -o etime $pid | sed -e '1d' | tail -n 1`
  122. echo ProcessUpTime: $elapsed
  123. mem=`free | head -n 3 | tail -n 1 | awk '{print $3,$4}'`
  124. cpu=`vmstat 1 2 | tail -n 1 | awk '{print $15}'`
  125. echo CPU-Idle: $cpu%
  126. cuptime=`uptime | cut -f 1,2 -d ','`
  127. echo ComputerUpTime: $cuptime
  128. echo ---SpaceUsedAndFree---
  129. swap=`free | tail -n 1 | awk '{print $3,$4}'`
  130. echo Physical Memory: $mem
  131. echo Swap: $swap
  132. for name in `df -l | tail -n +2 | awk '{if(NF>=4) print $NF}'`
  133. do
  134. arr0[i]=$name
  135. i=$((i+1))
  136. done
  137. i=0
  138. for used in `df -l | tail -n +2 | awk '{if(NF>=4) print $(NF-3)}'`
  139. do
  140. arr1[i]=$used
  141. i=$((i+1))
  142. done
  143. i=0
  144. for free in `df -l | tail -n +2 | awk '{if(NF>=4) print $(NF-2)}'`
  145. do
  146. arr2[i]=$free
  147. i=$((i+1))
  148. done
  149. for j in $(seq 0 $((i-1)))
  150. do
  151. echo ${arr0[$j]}: ${arr1[$j]} ${arr2[$j]}
  152. done
  153. fi