<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gur</title>
    <description>The latest articles on DEV Community by Gur (@gur5).</description>
    <link>https://dev.to/gur5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3206163%2F74219e87-794b-46ff-b625-6f6e4fb34750.webp</url>
      <title>DEV Community: Gur</title>
      <link>https://dev.to/gur5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gur5"/>
    <language>en</language>
    <item>
      <title>How to Find a File in Linux Using Find Command</title>
      <dc:creator>Gur</dc:creator>
      <pubDate>Sat, 07 Jun 2025 07:11:38 +0000</pubDate>
      <link>https://dev.to/gur5/how-to-find-a-file-in-linux-using-find-command-12ah</link>
      <guid>https://dev.to/gur5/how-to-find-a-file-in-linux-using-find-command-12ah</guid>
      <description>&lt;p&gt;The find command in Linux is used to search for files and directories based on name, type, size, date, or other conditions. It scans the specified directory and its sub directories to locate files matching the given criteria.&lt;br&gt;
find command uses are:&lt;br&gt;
• Search based on modification time (e.g., files edited last week).&lt;br&gt;
• Locate files with specific permissions or content.&lt;br&gt;
• Automate tasks like deleting or executing commands on found files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax of find Command in Linux&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;find  [path...] [option] [expression]&lt;br&gt;
find  . -name filename&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
• &lt;strong&gt;Path&lt;/strong&gt;: Where to start searching (e.g., ~/Documents).&lt;br&gt;
• &lt;strong&gt;Options&lt;/strong&gt;: Refine your search (e.g., -type for files/directories).&lt;br&gt;
• &lt;strong&gt;Expression&lt;/strong&gt;: Criteria like filenames or sizes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;case 1. how to search based on their size&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;M for mb&lt;br&gt;
        k for kb&lt;br&gt;
        G for gb&lt;br&gt;
        c for byte&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find /path/ -size 50M

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;case 2. how to find only file or only directory in a given path?&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;f for files&lt;br&gt;
        d for directory&lt;br&gt;
        l for symbolic link&lt;br&gt;
        b for block device&lt;br&gt;
        s for socket&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path -type f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;case 3. how to search a file based on it's name&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        find /path -name &amp;lt;dilename&amp;gt; # exect name mention
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;case 4. how to ignore upper &amp;amp; lower case in file name while searching files ?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         find /path -iname &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 5. How to search files for a given user only ?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find /path –user &amp;lt;username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 6. How to search a file based on the inode number ?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find /path inum &amp;lt;inode_no._of_file&amp;gt;
    ls -li # check inode number

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 7. How to search a based on the no. of links?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path -links &amp;lt;no._of_link&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 8. How to search a based on their permission&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find /path -perm /u=r
    find /path -perm 777

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 9. How to search all the files which start with letter a?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path -iname  “a*”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 10. How to search all the files which are modified/created after last.txt file?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path -newer last.txt 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 11. How to search all the empty files in a given directory?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path -empty
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 12. How to search all the empty files in a given directory and at the same time delete them?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path -empty -exec rm {} \;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 13. How to search all the files whose size are between 1-50MB ?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path  -size +1M -size -50M
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case 14. How to search  15 days old files&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    find /path -mtime 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Shell Scripting useful for Production</title>
      <dc:creator>Gur</dc:creator>
      <pubDate>Sun, 25 May 2025 15:20:33 +0000</pubDate>
      <link>https://dev.to/gur5/shell-scripting-useful-for-production-27nf</link>
      <guid>https://dev.to/gur5/shell-scripting-useful-for-production-27nf</guid>
      <description>&lt;p&gt;A shell script is a text file containing a series of commands that are executed by a Unix/Linux shell (command-line interpreter). It automates repetitive tasks, combines multiple commands, and can include programming constructs like loops, conditionals, and functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of Shell Scripting:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Automation — Runs commands without manual input.&lt;/li&gt;
&lt;li&gt;Batch Processing — Executes multiple commands sequentially.&lt;/li&gt;
&lt;li&gt;Scripting Language — Supports variables, loops, and conditionals.&lt;/li&gt;
&lt;li&gt;Reusability — Scripts can be saved and reused.&lt;/li&gt;
&lt;li&gt;Customization — Can take user input and generate dynamic output.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  1. Backup Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir source
touch /source/1.txt /source/2.txt # or cd /source/ &amp;amp;&amp;amp; touch 1.txt 2.txt
mkdir destination
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#! /bin/bash
SOURCE="/home/ubuntu/source"
DESTINATION="/home/ubuntu/destination"
DATE=$(date +%Y-%m-%d_%H-%M-%S)

#Create backup directory and copy files
mkdir -p $DESTINATION/$DATE
cp -r $SOURCE $DESTINATION/$DATE
echo "Backup completed on $DATE"

*or*
cp -r "$SOURCE" "$DESTINATION/$DATE" &amp;amp;&amp;amp; echo "Backup succeeded on $DATE" || echo "Backup failed on $DATE" &amp;gt;&amp;amp;2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chmod +x backup.sh
./backup.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• SOURCE: The directory to be backed up.&lt;br&gt;
• DESTINATION: The directory where the backup will be stored.&lt;br&gt;
• DATE: Captures the current date and time to create a unique backup folder.&lt;br&gt;
• mkdir -p $DESTINATION/$DATE: Creates the backup directory if it does not exist.&lt;br&gt;
• cp -r $SOURCE $DESTINATION/$DATE: Copies the contents of the source directory&lt;br&gt;
to the backup directory.&lt;br&gt;
• echo "Backup completed on $DATE": Outputs a message indicating the completion&lt;br&gt;
of the backup.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Scheduling with Cron
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;To run the backup script at regular intervals, use crontab -e to edit the crontab file
and add:
* * * * * /path/to/backup_script.sh 
This example runs the script every minute. Adjust the schedule as needed.

Remove or Disable the Cron Job
crontab -e
Method 1. Delete the line containing your backup script and save

Method 2. # * * * * * /path/to/backup_script.sh # add # and save

Method 3. crontab -r # Delete your entire crontab

Method 4: Stop the Cron Service
        sudo systemctl stop cron    # Ubuntu/Debian
        sudo systemctl stop crond  # CentOS/RHEL

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. Disk Usage Check Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
THRESHOLD=80
# Check disk usage and print a warning if usage is above the threshold
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' |
while read output;
do
usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
partition=$(echo $output | awk '{ print $2 }')
if [ $usage -ge $THRESHOLD ]; then
echo "Warning: Disk usage on $partition is at ${usage}%"
fi
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• THRESHOLD: Sets the disk usage percentage threshold.&lt;br&gt;
• df -H: Lists disk usage in human-readable format.&lt;br&gt;
• grep -vE '^Filesystem|tmpfs|cdrom': Filters out unnecessary lines.&lt;br&gt;
• awk '{ print $5 " " $1 }': Extracts the usage percentage and partition name.&lt;br&gt;
• while read output: Iterates over each line of the filtered output.&lt;br&gt;
• usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1): Extracts the usage&lt;br&gt;
percentage.&lt;br&gt;
• partition=$(echo $output | awk '{ print $2 }'): Extracts the partition name.&lt;br&gt;
• if [ $usage -ge $THRESHOLD ]; then: Checks if the usage exceeds the threshold.&lt;br&gt;
• echo "Warning: Disk usage on 𝑝𝑎𝑟𝑡𝑖𝑡𝑖𝑜𝑛𝑖𝑠𝑎𝑡{usage}%": Prints a warning message&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  3. Service Health Check Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
SERVICE="nginx"
# Check if the service is running, if not, start it
if systemctl is-active --quiet $SERVICE; then
echo "$SERVICE is running"
else
echo "$SERVICE is not running"
systemctl start $SERVICE
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• SERVICE: The name of the service to check.&lt;br&gt;
• systemctl is-active --quiet $SERVICE: Checks if the service is running.&lt;br&gt;
• echo "$SERVICE is running": Prints a message if the service is running.&lt;br&gt;
• systemctl start $SERVICE: Starts the service if it is not running.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install nginx
sudo systemctl status nginx
./service-health.sh
sudo systemctl stop nginx

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. Network Connectivity Check Script
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;touch output.txt&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
HOST="google.com"
# Output file
OUTPUT_FILE="/home/ubuntu/output.txt"
# Check if the host is reachable
if ping -c 1 $HOST &amp;amp;&amp;gt; /dev/null
then
echo "$HOST is reachable" &amp;gt;&amp;gt; $OUTPUT_FILE
else
echo "$HOST is not reachable" &amp;gt;&amp;gt; $OUTPUT_FILE
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• HOST: The hostname to check.&lt;br&gt;
• OUTPUT_FILE: The file to write the output to.&lt;br&gt;
• ping -c 1 $HOST &amp;amp;&amp;gt; /dev/null: Pings the host once, suppressing output.&lt;br&gt;
• echo "$HOST is reachable" &amp;gt;&amp;gt; $OUTPUT_FILE: Writes to the output file if the host&lt;br&gt;
is reachable.• echo "$HOST is not reachable" &amp;gt;&amp;gt; $OUTPUT_FILE: Writes to the output file if the&lt;br&gt;
host is not reachable.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  5. Database Backup Script
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Install MySQL:
sudo apt install mysql-server -y

Set up MySQL password:
sudo mysql -u root

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY
'root';
FLUSH PRIVILEGES;
&amp;gt; show databases;
create database mydatabase;
exit

mkdir /home/ubuntu/db_backup #  for this /path/to/backup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Method 1.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
DB_NAME="mydatabase"
BACKUP_DIR="/path/to/backup"
DATE=$(date +%Y-%m-%d_%H-%M-%S)

# Perform a database backup and save it to the backup directory
mysqldump -u root -p $DB_NAME &amp;gt; $BACKUP_DIR/$DB_NAME-$DATE.sql
echo "Database backup completed: $BACKUP_DIR/$DB_NAME-$DATE.sql"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Method 2. auto fill password
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
DB_NAME="mydatabase"
BACKUP_DIR="/path/to/backup"
DATE=$(date +%Y-%m-%d_%H-%M-%S)
DB_PASSWORD="root"  # Added password variable

# Perform the backup (password provided automatically)
mysqldump -u root -p"$DB_PASSWORD" "$DB_NAME" &amp;gt; "$BACKUP_DIR/$DB_NAME-$DATE.sql"
echo "Database backup completed: $BACKUP_DIR/$DB_NAME-$DATE.sql"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  method 3. For production and Security :
&lt;/h4&gt;

&lt;p&gt;vim ~/.my.cnf&lt;br&gt;
chmod 600 ~/.my.cnf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[mysqldump]
user=root
password=yourpassword
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
DB_NAME="mydatabase"
BACKUP_DIR="/path/to/backup"
DATE=$(date +%Y-%m-%d_%H-%M-%S)

mysqldump "$DB_NAME" &amp;gt; "$BACKUP_DIR/$DB_NAME-$DATE.sql"
echo "Backup completed: $BACKUP_DIR/$DB_NAME-$DATE.sql"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  6. System Uptime Check Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
# Print the system uptime
uptime -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• uptime -p: Prints the system uptime in a human-readable format.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  7. Listening Ports Script
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Installation
&lt;/h4&gt;

&lt;p&gt;Install net-tools:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install net-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
# List all listening ports and the associated services
netstat -tuln | grep LISTEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Explanation
• netstat -tuln: Lists all TCP and UDP listening ports.
• grep LISTEN: Filters the output to show only listening ports.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  8. Automatic Package Updates Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
# Update system packages and clean up unnecessary packages
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade -y &amp;amp;&amp;amp; sudo apt-get autoremove -y &amp;amp;&amp;amp; sudo apt-get clean
echo "System packages updated and cleaned up"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• apt-get update: Updates the package list.&lt;br&gt;
• apt-get upgrade -y: Upgrades all installed packages.&lt;br&gt;
• apt-get autoremove -y: Removes unnecessary packages.&lt;br&gt;
• apt-get clean: Cleans up the package cache.&lt;br&gt;
• echo "System packages updated and cleaned up": Outputs a message indicating&lt;br&gt;
the completion of the update and cleanup.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  9. HTTP Response Times Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
URLS=("https://www.google.com/" "https://www.linkedin.com/")
# Check HTTP response times for multiple URLs
for URL in "${URLS[@]}"; do
RESPONSE_TIME=$(curl -o /dev/null -s -w '%{time_total}\n' $URL)
echo "Response time for $URL: $RESPONSE_TIME seconds"
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• URLS: An array of URLs to check.&lt;br&gt;
• for URL in "${URLS[@]}": Iterates over each URL.&lt;br&gt;
• curl -o /dev/null -s -w '%{time_total}\n' $URL: Uses curl to fetch the URL and&lt;br&gt;
measure the total response time.&lt;br&gt;
• echo "Response time for $URL: $RESPONSE_TIME seconds": Prints the response&lt;br&gt;
time for each URL.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  10. Monitor System Processes and Memory Usage Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
# Monitor system processes and their memory usage
ps aux --sort=-%mem | head -n 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Explanation&lt;br&gt;
• ps aux: Lists all running processes.&lt;br&gt;
• --sort=-%mem: Sorts the processes by memory usage in descending order.&lt;br&gt;
• head -n 10: Displays the top 10 processes by memory usage.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  11. System Monitoring Script:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

threshold=90

# Monitor CPU usage and trigger alert if threshold exceeded
# Method 1: Using vmstat (most reliable)
cpu_usage=$(vmstat 1 2 | tail -1 | awk '{print 100-$15}' | cut -d. -f1)

# Alternative method using top (if vmstat doesn't work)
# cpu_usage=$(top -bn1 | grep -i "cpu(s)" | awk '{gsub(/%us,|%user,|%/, ""); for(i=1;i&amp;lt;=NF;i++) if($i ~ /^[0-9]+\.?[0-9]*$/) {print $i; exit}}')

# Debug: Show what we captured
echo "Current CPU usage: $cpu_usage%"

if [ ! -z "$cpu_usage" ] &amp;amp;&amp;amp; [ "$cpu_usage" -gt "$threshold" ]; then
    echo "HIGH CPU ALERT: Usage is $cpu_usage% (threshold: $threshold%)"
    # Add alert/notification logic here
    # Example: mail -s "High CPU Alert" admin@example.com &amp;lt; /dev/null
    # Example: logger "High CPU usage detected: $cpu_usage%"
else
    echo "CPU usage normal: $cpu_usage%"
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;use stress cmd for better results&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
  </channel>
</rss>
