Project 1:Create a shell script for archiving older log files

Question:To create a shell script for archiving older log files, you can use tools like find to locate files that are older than a specified threshold and then move or compress those files to an archive directory.

#!/bin/bash
#Variables
path=/home/risvarsh
Days=10
log=/home/risvarsh/pratice

#check if the directory present or not
if [ ! -d $path ]
then 
    echo "directory does not exist : $path"
    exit 1
fi

#Create archive folder if not present
if  [ ! -d $path/archive ]
then
    mkdir $path/archive
fi

#Find the files have 10 days older

find "$log" -type f -mtime +$Days -exec mv {} "$path/archive" \;
echo "Log files older than ${Days} days have been archived."