Shell scripting project

Shell scripting project

Scrutiny of Linux server

Certainly! Here's a step-by-step explanation of how to perform scrutiny of a Linux server using a shell script:

Step 1: Create a new shell script file Create a new file using a text editor, such as "server_scrutiny.sh". This will be your shell script file.

Step 2: Define the shebang Start the script with the shebang (#!/bin/bash) at the top. It informs the system that the script should be executed using the Bash shell.

#!/bin/bash

Step 3: Define section printing function Next, define a function called "print_section" that will print a section heading with a separator line. This will enhance the readability of the output. Here's the function definition:

print_section() {
    echo ""
    echo "=== $1 ==="
    echo "========================================="
}

The function takes one parameter, $1, which represents the section heading. It uses echo to print the section heading and a separator line.

Step 4: Print system information Call the print_section function to print a section heading for "System Information". Then, use the hostnamectl command to display the system information.

print_section "System Information"
hostnamectl

Step 5: Print disk usage Print a section heading for "Disk Usage" using the print_section function. Then, use the df -h command to display the disk usage information.

print_section "Disk Usage"
df -h

Step 6: Print memory usage Print a section heading for "Memory Usage" using the print_section function. Then, use the free -h command to display the memory usage information.

print_section "Memory Usage"
free -h

Step 7: Print CPU usage Print a section heading for "CPU Usage" using the print_section function. Then, use the top -bn 1 | head -n 10 command to display the CPU usage information.

print_section "CPU Usage"
top -bn 1 | head -n 10

Step 8: Print network connections Print a section heading for "Network Connections" using the print_section function. Then, use the netstat -tulpn command to display the network connections information.

print_section "Network Connections"
netstat -tulpn

Step 9: Print running processes Print a section heading for "Running Processes" using the print_section function. Then, use the ps aux command to display the running processes information.

print_section "Running Processes"
ps aux | head -15

Step 10: Print system log Print a section heading for "System Log" using the print_section function. Then, use the tail /var/log/syslog command to display the system log information.

print_section "System Log"
tail /var/log/syslog

Step 11: End the script Add a comment indicating the end of the script.

# End of Script

Step 12: Save and make the script executable Save the file. Then, make the script executable using the following command:

chmod +x server_scrutiny.sh

Step 13: Execute the script Run the script by executing the following command:

./server_scrutiny.sh

The script will execute each section sequentially, printing the corresponding information to the console.

After combining and modification as per you beautifying skill, it will look like this:

OUTPUTS:

Feel free to modify or enhance the script as needed to suit your specific requirements for scrutinizing the Linux.

Conclusion:

Performing thorough scrutiny of a Linux server is crucial for ensuring its security, stability, and optimal performance. By leveraging shell scripting, you can automate various steps of the scrutiny process, from gathering system information to monitoring resources and analyzing security measures. The flexibility and power of shell scripting enable you to tailor your scrutiny process to the specific needs of your Linux server. By following the step-by-step instructions provided in this blog, you can establish a robust and efficient system scrutiny framework, ensuring that your Linux server remains secure and performs at its best.

Get Connected:

If you have any suggestion about this post feel free to let me know and be updated on my blog in the following ways:

LinkedIn Twitter Github

#TrainWithShubham #DevOps #chatgpt #AI #devops #devopsengineer #devops2023 #devopscommunity #devopslife #devopsnotes #DevOpsGuys #DevOpsHandbook #devopsinuk #shellscript #linux