Question
1-server-health.sh There are two (2) problems with this script. The first involves an error in the output about a missing command. The second is the
1-server-health.sh There are two (2) problems with this script. The first involves an error in the output about a missing command. The second is the fact that the vmstat command should include a timestamp for each line of output. To address the second problem you will need to read the documentation for vmstat. Below is example output of the script.
tmoyer2@itis-3246:~/scripting-2$ ./1-server-health.sh Tue Sep 11 12:50:28 EDT 2018 uptime: 12:50:28 up 5 min, 1 user, load average: 0.18, 0.59, 0.33 Currently connected: 12:50:28 up 5 min, 1 user, load average: 0.18, 0.59, 0.33 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT tmoyer2 tty7 :0 12:46 4:51 4.42s 0.01s /bin/sh /etc/xdg/xfce4/xinitrc -- /etc/X11/xinit/xserverrc -------------------- Last logins: tmoyer2 tty7 Tue Sep 11 12:46 gone - no logout :0 reboot system boot Tue Sep 11 12:45 still running 4.15.0-33-generic tmoyer2 tty7 Thu Sep 6 10:07 - 13:20 (03:13) :0 -------------------- Disk and memory usage: Free/total disk: 452M / 452M Free/total memory: 888 / 962 MB -------------------- OOM errors since Sep 6 10:03 : 39 -------------------- Utilization and most expensive processes: top - 12:50:28 up 5 min, 1 user, load average: 0.18, 0.59, 0.33 Tasks: 247 total, 1 running, 147 sleeping, 0 stopped, 0 zombie %Cpu(s): 13.2 us, 7.0 sy, 3.3 ni, 55.6 id, 20.5 wa, 0.0 hi, 0.5 si, 0.0 st PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 159600 6980 5360 S 0.0 0.7 0:01.17 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0 -------------------- Open TCP ports: Starting Nmap 7.60 ( https://nmap.org ) at 2018-09-19 16:26 EDT Nmap scan report for localhost (127.0.0.1) Host is up (0.000031s latency). Not shown: 65534 closed ports PORT STATE SERVICE 631/tcp open ipp Nmap done: 1 IP address (1 host up) scanned in 0.51 seconds -------------------- Current connections: Total: 1366 (kernel 0) TCP: 3 (estab 0, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0 Transport Total IP IPv6 * 0 - - RAW 1 0 1 UDP 7 5 2 TCP 3 2 1 INET 11 7 4 FRAG 0 0 0 -------------------- processes: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2 0.0 0.0 0 0 ? S 12:45 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I 12:45 0:00 \_ [kworker/0:0] root 4 0.0 0.0 0 0 ? I< 12:45 0:00 \_ [kworker/0:0H] ... tmoyer2 11216 0.0 0.3 20456 3200 pts/1 S+ 12:50 0:00 \_ /bin/bash ./1-server-health.sh tmoyer2 11241 0.0 0.4 47648 4056 pts/1 R+ 12:50 0:00 \_ ps auxf --width=200 -------------------- vmstat: procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp----- r b swpd free buff cache si so bi bo in cs us sy id wa st EDT 0 0 59648 96900 12592 376700 19 212 5995 5028 493 2358 16 8 56 20 0 2018-09-11 12:50:29 0 0 59648 96792 12592 376696 0 0 0 0 155 318 4 1 95 0 0 2018-09-11 12:50:30 0 0 59648 96792 12592 376696 0 0 0 0 280 581 6 1 93 0 0 2018-09-11 12:50:31 0 0 59648 96792 12592 376696 0 0 0 0 240 612 4 0 96 0 0 2018-09-11 12:50:32 0 0 59648 96792 12592 376696 0 0 0 0 271 371 2 2 96 0 0 2018-09-11 12:50:33
The script is below:
#!/bin/bash date; echo "uptime: $(uptime)" echo "Currently connected:" w echo "--------------------" echo "Last logins:" last -a |head -3 echo "--------------------" echo "Disk and memory usage:" df -h | xargs | awk '{print "Free/total disk: " $11 " / " $9}' free -m | xargs | awk '{print "Free/total memory: " $17 " / " $8 " MB"}' echo "--------------------" start_log=$(head -1 /var/log/syslog |cut -c 1-12) oom=$(grep -ci kill /var/log/syslog) echo -n "OOM errors since $start_log :" $oom echo "" echo "--------------------" echo "Utilization and most expensive processes:"
top -b |head -3 echo top -b |head -10 |tail -4 echo "--------------------" echo "Open TCP ports:" nmap -p- -T4 127.0.0.1 echo "--------------------" echo "Current connections:" ss -s echo "--------------------"
echo "processes:" ps auxf --width=200 echo "--------------------" echo "vmstat:" vmstat 1 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started