Advertisement
sandervanvugt

collbash dec20

Dec 3rd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.21 KB | None | 0 0
  1. ##### script 1 modification[root@localhost cool-bash]# cat 1_cpu-hog
  2. #!/bin/bash
  3. # Script that monitors the top-active process. The script sends an email to the user root if
  4. # utilization of the top active process goed beyond 80%. Of course, this script can be tuned to
  5. # do anything else in such a case.
  6. #
  7. # Start the script, and it will run forever.
  8.  
  9. while true
  10. do
  11. # Check every 60 seconds if we have a process causing high CPU load
  12. sleep 5
  13. USAGE=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1`
  14. CPU=$(echo $USAGE | awk '{ print $1 }')
  15. CPU=${CPU%.*}
  16. PID=$(echo $USAGE | awk '{ print $2 }')
  17. PNAME=$(echo $USAGE | awk '{ print $3 }')
  18.  
  19. echo debugging...
  20. echo CPU is $CPU
  21. echo PID is $PID
  22. echo PNAME is $PNAME
  23. read
  24.  
  25. # Only if we have a high CPU load on one process, run a check within 7 seconds
  26. # In this check, we should monitor if the process is still that active
  27. # If that's the case, root gets a message
  28. if [ $USAGE -gt 80 ]
  29. then
  30. USAGE1=$USAGE
  31. PID1=$PID
  32. PNAME1=$PNAME
  33. sleep 7
  34. USAGE2=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{ print $1 } '`
  35. USAGE2=${USAGE2%.*}
  36. PID2=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{print $2 }'`
  37. PNAME2=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{print $3 }'`
  38.  
  39. # Now we have variables with the old process information and with the
  40. # new information
  41.  
  42. [ $USAGE2 -gt 80 ] && [ $PID1 = $PID2 ] && logger -s process $PID1 has high load
  43. fi
  44. done
  45.  
  46. HISTORY
  47. [root@localhost cool-bash]# history
  48. 1 cd bash-scripting/
  49. 2 vim lab8
  50. 3 ls -lrt
  51. 4 vim script9b
  52. 5 vim laB8
  53. 6 [[ -r /etc/shadow ]] && echo its readable
  54. 7 [[ -erm 444 /etc/shadow ]] && echo its readable
  55. 8 [[ -perm 444 /etc/shadow ]] && echo its readable
  56. 9 stat -L -c "%a %G %U" /etc/shadow
  57. 10 vim lab9
  58. 11 chmod +x lab9
  59. 12 ./lab9
  60. 13 vim lab9
  61. 14 ./lab9
  62. 15 vim lab9
  63. 16 ./lab9
  64. 17 vim lab9
  65. 18 man exec
  66. 19 cd ..
  67. 20 git clone https://github.com/sandervanvugt/cool-bash
  68. 21 cd cool-bash/
  69. 22 ls
  70. 23 ./3_choosedir
  71. 24 vim 3_choosedir
  72. 25 vim 3b_users
  73. 26 chmod +x 3b_users
  74. 27 vim 3b_users
  75. 28 ./3b_users
  76. 29 ls
  77. 30 vim 1_cpu-hog
  78. 31 vim 2_what_is_it
  79. 32 vim 4_reboot-test.sh
  80. 33 vim lab7
  81. 34 chmod +x lab7
  82. 35 ./lab7
  83. 36 bg
  84. 37 cat lab7
  85. 38 ls
  86. 39 vim 8_makeusr
  87. 40 ./8_makeusr
  88. 41 ./8_makeusr -u 1200 -i iemand linda
  89. 42 cat /etc/passwd
  90. 43 vim 8_makeusr
  91. 44 less 8_makeusr
  92. 45 vim doit
  93. 46 chmod +x doit
  94. 47 ./doit
  95. 48 ./doit -u
  96. 49 ./doit -l
  97. 50 ./doit -p
  98. 51 cat doit
  99. 52 yum install -y git vim bash-completion
  100. 53 git clone https://github.com/sandervanvugt/bash-scripting
  101. 54 cd bash-scripting/
  102. 55 ls
  103. 56 vim script1
  104. 57 script1
  105. 58 echo $PATH
  106. 59 pwd
  107. 60 ./script1
  108. 61 chmod +x script1
  109. 62 ./script1
  110. 63 ls
  111. 64 echo $?
  112. 65 ls kuerhiughiuhuih
  113. 66 echo $?
  114. 67 help
  115. 68 cd /usr/bin
  116. 69 ls
  117. 70 which ls
  118. 71 which cd
  119. 72 type cd
  120. 73 type ls
  121. 74 echo $?
  122. 75 cd
  123. 76 cd bash-scripting/
  124. 77 ./countdown 2
  125. 78 vim lab1.sh
  126. 79 chmod +x lab1.sh
  127. 80 ./lab1.sh
  128. 81 cat lab1.sh
  129. 82 ls
  130. 83 vim script2
  131. 84 ./script2
  132. 85 chmod +x script*
  133. 86 ./script2
  134. 87 cat script2
  135. 88 . script2
  136. 89 pwd
  137. 90 cd -
  138. 91 vim script2b
  139. 92 vim colors
  140. 93 chmod + script2b
  141. 94 ./script2b
  142. 95 chmod +x script2b
  143. 96 ./script2b
  144. 97 vim colors
  145. 98 ./script2b
  146. 99 yum search network
  147. 100 yum search network | grep script
  148. 101 yum install -y network-scripts
  149. 102 cd /etc/init.d
  150. 103 ls
  151. 104 vim network
  152. 105 cd /etc/sysconfig/
  153. 106 ls
  154. 107 cd network-scripts/
  155. 108 ls
  156. 109 cat ifcfg-ens33
  157. 110 cd
  158. 111 cd bash-scripting/
  159. 112 vim script2
  160. 113 cat script2b
  161. 114 cat colors
  162. 115 ./countdown 12
  163. 116 history
  164. 117 sleep 30; ./countdown 11
  165. 118 vim lab2
  166. 119 vim script3
  167. 120 ./script3 a b c d e f g h i j k l m n b
  168. 121 cat script3
  169. 122 vim script3
  170. 123 ./script3 a b c d e f g h i j k l m
  171. 124 grep '^root$' /etc/* 2>/dev/null
  172. 125 ./countdown 3
  173. 126 vim lab3
  174. 127 chmod +x lab3
  175. 128 vim lab3
  176. 129 ./lab3 sander van vugt
  177. 130 ./lab3 "sander van vugt"
  178. 131 vim script4
  179. 132 ./script4 a b c d
  180. 133 vim script4
  181. 134 ./script4 a b c d
  182. 135 vim script4
  183. 136 touch hello
  184. 137 ls -l hello
  185. 138 ./countdown 3
  186. 139 vim lab4
  187. 140 chmod +x lab4
  188. 141 ./lab4
  189. 142 ./lab4 a b c d
  190. 143 ls
  191. 144 for i in a b c d; do rm $i; done
  192. 145 for i in a b c d; do rm -f $i; done
  193. 146 ls
  194. 147 for i in lab{1..4}; do cat $i; done
  195. 148 for i in lab{1..4}; do echo ######## $i; cat $i; done
  196. 149 for i in lab{1..4}; do echo '######## $i'; cat $i; done
  197. 150 for i in lab{1..4}; do echo '########' $i; cat $i; done
  198. 151 history
  199. 152 vim script5
  200. 153 cd /lib/modules
  201. 154 ls
  202. 155 ls -l
  203. 156 uname -r
  204. 157 cd ~/bash-scripting/
  205. 158 vim script5
  206. 159 ./script5
  207. 160 ./countdown 2
  208. 161 date
  209. 162 date +%d-%m-%Y
  210. 163 vim lab5
  211. 164 chmod +x lab5
  212. 165 ./lab5
  213. 166 ls
  214. 167 vim script6
  215. 168 ./script6 /usr/bin/blah
  216. 169 vim script6
  217. 170 ./script6 /usr/bin/blah
  218. 171 cat script7
  219. 172 ./countdown 3
  220. 173 vim lab7
  221. 174 chmod +x lab7
  222. 175 ./lab7 sander van
  223. 176 vim lab7
  224. 177 ./lab7 sander van
  225. 178 vim lab7
  226. 179 ./lab7 sander van
  227. 180 vim lab7
  228. 181 ./lab7 sander van
  229. 182 vim lab7
  230. 183 ./lab7 sander van
  231. 184 vim lab7
  232. 185 ./lab7 sander van
  233. 186 vim lab7
  234. 187 cat lab5
  235. 188 cat lab6
  236. 189 cat lab7
  237. 190 vim script7
  238. 191 vim script8
  239. 192 cut -d : -f 1 /etc/passswd
  240. 193 cut -d : -f 1 /etc/passwd
  241. 194 useradd alexander
  242. 195 useradd alex
  243. 196 useradd lex
  244. 197 useradd xander
  245. 198 grep lex /etc/passwd
  246. 199 cut -f 1 -d : /etc/passwd | grep '^lex$'
  247. 200 ./script8 lex
  248. 201 ./script8 alexa
  249. 202 vim /etc/init.d/network
  250. 203 vim script8
  251. 204 ./script8 alexa
  252. 205 ./script8 alex
  253. 206 vim script8
  254. 207 ./countdown 2
  255. 208 vim laB8
  256. 209 chmod +x laB8
  257. 210 ./laB8
  258. 211 vim laB8
  259. 212 ./laB8
  260. 213 vim laB8
  261. 214 ./laB8
  262. 215 cat lab7
  263. 216 cat laB8
  264. 217 man test
  265. 218 test -f /etc/hosts
  266. 219 echo $0
  267. 220 echo $?
  268. 221 test -f /etc/hosts
  269. 222 echo $?
  270. 223 test -f kuwrhkug
  271. 224 echo $?
  272. 225 [ -f khiuhiuh ]
  273. 226 echo $?
  274. 227 [ -f /etc/hosts ]
  275. 228 echo $?
  276. 229 man test
  277. 230 [[ -f /etc/hosts ]]
  278. 231 echo $?
  279. 232 [[ -f khkuhkuh ]]
  280. 233 echo $?
  281. 234 [ 0 == 0 ]
  282. 235 [ 0 == 1 ]
  283. 236 echo $?
  284. 237 [[ 0 == 1 ]]
  285. 238 vim script9
  286. 239 ./script9
  287. 240 ./script9 juh
  288. 241 vim script9b
  289. 242 chmod +x script9b
  290. 243 ./script9b
  291. 244 ./script9b khk
  292. 245 vim script9b
  293. 246 ./script9b khk
  294. 247 ./script9b /etc/hosts
  295. 248 vim script9b
  296. 249 ./script9b /etc/hosts
  297. 250 ./script9b khk
  298. 251 cat script9b
  299. 252 vim /etc/init.d/network
  300. 253 ./countdown 12
  301. 254 [ -r /etc/shadow ] && echo "File is insecure" || echo "File is secure"
  302. 255 ls -l /etc/shadow
  303. 256 man test
  304. 257 [ -w /etc/shadow ] && echo "File is insecure" || echo "File is secure"
  305. 258 [ -x /etc/shadow ] && echo "File is insecure" || echo "File is secure"
  306. 259 vim countdown
  307. 260 vim script10
  308. 261 ./script10 5
  309. 262 ./countdown 5
  310. 263 vim lab9
  311. 264 ./lab9
  312. 265 vim lab9
  313. 266 vim lab10
  314. 267 ./lab10
  315. 268 chmod +x lab10
  316. 269 ./lab10
  317. 270 ls
  318. 271 cat lab9
  319. 272 cat lab10
  320. 273 vim script11
  321. 274 ./script11 1
  322. 275 bash -x ./script11 1
  323. 276 vim script11
  324. 277 ./script11
  325. 278 bash -x ./script11 1
  326. 279 vim script11
  327. 280 ./script11
  328. 281 bash -x ./script11
  329. 282 vim script11
  330. 283 ./script11
  331. 284 ./script11 1
  332. 285 vim script11
  333. 286 vim script12
  334. 287 ./script12
  335. 288 vim script12
  336. 289 ./script12
  337. 290 vim script12
  338. 291 ./script12
  339. 292 cat script12
  340. 293 history
  341. 294 poweroff
  342. 295 history
  343. 296 exit
  344. 297 cd cool-bash/
  345. 298 vim 3_choosedir
  346. 299 ./3_choosedir
  347. 300 vim 3_choosedir
  348. 301 man test
  349. 302 vim 3_choosedir
  350. 303 ./3_choosedir
  351. 304 vim 3_choosedir
  352. 305 cd cool-bash/
  353. 306 cd ../bash-scripting/
  354. 307 ./countdown 5
  355. 308 history
  356. 309 ls
  357. 310 rm -rf cool-bash/
  358. 311 echo hello world
  359. 312 git clone https://github.com/sandervanvugt/cool-bash
  360. 313 cd cool-bash/
  361. 314 ls
  362. 315 vim 1_cpu-hog
  363. 316 ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{ print $1 } '
  364. 317 ps -eo pcpu,pid -o comm=
  365. 318 ps -eo pcpu,pid -o comm= | head
  366. 319 ps -eo pcpu,pid -o comm= | sort -k1 -n -r
  367. 320 ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head
  368. 321 vim 1_cpu-hog
  369. 322 yum install -y xmail
  370. 323 yum install -y mailx
  371. 324 vim 1_cpu-hog
  372. 325 dd if=/dev/zero of=/dev/null &
  373. 326 ./1_cpu-hog
  374. 327 vim 1_cpu-hog
  375. 328 bash -x 1_cpu-hog
  376. 329 vim 1_cpu-hog
  377. 330 ./1_cpu-hog
  378. 331 vim 1_cpu-hog
  379. 332 cat 1_cpu-hog
  380. 333 vim 1_cpu-hog
  381. 334 cp ../bash-scripting/countdown .
  382. 335 ./countdown 4
  383. 336 vim va.sh
  384. 337 va.sh /etc/hosts
  385. 338 chmod +x va.sh
  386. 339 ./va.sh /etc/hosts
  387. 340 ./va.sh /tmp
  388. 341 bash -x ./va.sh /tmp
  389. 342 vim 2_cv
  390. 343 ./2_cv /tmp
  391. 344 vim 3_choosedir
  392. 345 ./3_choosedir
  393. 346 vim 3_choosedir
  394. 347 ./3_choosedir
  395. 348 ./countdown 13
  396. 349 vim jc.sh
  397. 350 chmod +x jc.sh
  398. 351 ./jc.sh
  399. 352 ./jc.sh alice bob carol
  400. 353 vim 3_choosedir
  401. 354 ./3_choosedir
  402. 355 vim 4_reboot-test.sh
  403. 356 ./4_reboot-test.sh
  404. 357 cd cool-bash/
  405. 358 cd ../bash-scripting/
  406. 359 ls
  407. 360 vim kube-setup.sh
  408. 361 ./countdown 5
  409. 362 vim va.sh
  410. 363 man test
  411. 364 vim va.sh
  412. 365 cd ../cool-bash/
  413. 366 vim 4_reboot-test.sh
  414. 367 ./4_reboot-test.sh
  415. 368 vim 4_reboot-test.sh
  416. 369 ./4_reboot-test.sh
  417. 370 cd cool-bash/
  418. 371 vim 4_reboot-test.sh
  419. 372 vim jc.sh
  420. 373 vim jc2.sh
  421. 374 vim 5_today.sh
  422. 375 cd ../bash-scripting/
  423. 376 vim script6
  424. 377 ./script6 /usr/bin/blah
  425. 378 cd ../cool-bash/
  426. 379 vim jc2.sh
  427. 380 vim 5_today.sh
  428. 381 ./5_today.sh
  429. 382 vim 5_subst.sh
  430. 383 vim users
  431. 384 ./5_subst.sh
  432. 385 cat users
  433. 386 vim 5_subst.sh
  434. 387 vim users
  435. 388 ./5_subst.sh
  436. 389 cat users
  437. 390 cat users
  438. 391 time sed -i -e 's/lisa/bob/' users
  439. 392 cat users
  440. 393 strace -c sed -i -e 's/bob/lisa/' users
  441. 394 vim 5_subst.sh
  442. 395 ./countdown 12
  443. 396 vim jp.sh
  444. 397 history -w
  445. 398 cd cool-bash/
  446. 399 ls
  447. 400 vim 7a_trap
  448. 401 man 7 signals
  449. 402 man 7 signal
  450. 403 vim 7a_trap
  451. 404 ./7a_trap
  452. 405 vim 7a_trap
  453. 406 vim 7b_trap
  454. 407 ./7b_trap
  455. 408 ./countdown 3
  456. 409 vim lab7.sh
  457. 410 chmod +x lab7.sh
  458. 411 ./lab7.sh
  459. 412 man signal
  460. 413 man 7 signal
  461. 414 vim jp7.sh
  462. 415 vim jc7.sh
  463. 416 vim 8_makeusr
  464. 417 ./8_makeusr -u 1313 bill
  465. 418 vim 8_makeusr
  466. 419 ./8_makeusr -u 1313 bill
  467. 420 vim 8_makeusr
  468. 421 ./8_makeusr -u 1313 bill
  469. 422 tail -1 /etc/passwd
  470. 423 history
  471.  
  472.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement