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