Post by Shahana MS

Certified AWS AI Practitioner 🏅| AI-DS | Cloud Computing|Machine Learning | Pre-final Year Student|AWS×2| | B.Tech Student at SJCE| AWS X 4 badges

Day2 at #devOpschallenge This challenge comprises of the following: ✒️ Displaying messages and date : #!/bin/bash echo "Hello DevOps! Today's date and time is: $(date)" ✒️ Checking website status : #!/bin/bash # Define the website to check WEBSITE="https://www.learnxops.com" DOMAIN="learnxops.com" # Check website availability using curl if curl -Is "$WEBSITE" --max-time 5 | head -n 1 | grep -q "200\|301\|302"; then   echo "✅ Success: $WEBSITE is reachable via curl!" else   echo "⚠ Curl check failed, trying ping..."   # Check website availability using ping   if ping -c 2 -W 2 "$DOMAIN" > /dev/null 2>&1; then     echo "✅ Success: $DOMAIN is reachable via ping!"   else     echo "❌ Failure: $WEBSITE is not reachable via curl or ping."   fi fi ✒️ Validating file existence : #/bin/bash # Check if a filename argument is provided if [ $# -eq 0 ]; then   echo "❌ Error: No filename provided."   echo "Usage: ./check_file.sh "   exit 1 fi FILENAME="$1" # Check if the file exists if [ -f "$FILENAME" ]; then   echo "✅ File '$FILENAME' found. Displaying content:"   cat "$FILENAME" else   echo "❌ Error: File '$FILENAME' does not exist." fi ✒️Listing system processes : #!/bin/bash # Define output file OUTPUT_FILE="process_list.txt" # List all running processes and write to file ps aux > "$OUTPUT_FILE" # Print success message echo "✅ Process list saved to $OUTPUT_FILE" ✒️Checking/installing packages: #!/bin/bash # Define the list of packages to install PACKAGES=("git" "vim" "curl") # Loop through each package and check if it's installed for PACKAGE in "${PACKAGES[@]}"; do   if dpkg -l | grep -qw "$PACKAGE"; then     echo "✅ $PACKAGE is already installed."   else     echo "⏳ Installing $PACKAGE..."     sudo apt-get install -y "$PACKAGE" && \     echo "✅ $PACKAGE installed successfully." || \     echo "❌ Failed to install $PACKAGE."   fi done ✒️Monitoring system resources: #!/bin/bash # Define the log file LOG_FILE="resource_usage.log" echo "Monitoring CPU and Memory usage... Logs will be saved in $LOG_FILE" echo "Timestamp | CPU (%) | Memory (%)" > "$LOG_FILE" # Infinite loop to log system usage every 5 seconds while true; do   TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")   # Get CPU usage   CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}')   # Get Memory usage   MEM_USAGE=$(free | awk '/Mem/ {printf "%.2f", $3/$2 * 100}')   # Write data to the log file   echo "$TIMESTAMP | $CPU_USAGE | $MEM_USAGE" >> "$LOG_FILE"   # Wait for 5 seconds   sleep 5 done ✒️Cleaning old logs : ✒️Creating users : ✒️Extracting logs : ✒️Taking backups : The following commands are used : 📍 nano .sh - Open script in editor 📍chmod +x .sh - Make script executable 📍./.sh - Run script from the current directory #devopschallenge2 #Handsonexperience

Post contentPost contentPost contentPost contentPost contentPost content