Skip to content

Instantly share code, notes, and snippets.

@hypnguyen1209
Created December 18, 2021 13:54
Show Gist options
  • Save hypnguyen1209/e65e67d2db4618c548d2e6609a4a21af to your computer and use it in GitHub Desktop.
Save hypnguyen1209/e65e67d2db4618c548d2e6609a4a21af to your computer and use it in GitHub Desktop.
#!/bin/bash
dir_etc="/etc"
checklogs="/var/log/checketc.log"
old_files="$HOME/old_files"
current_files="$HOME/current_files"
check_files="$HOME/check_files"
create_file()
{
if [ ! -e $1 ]
then
touch $1
fi
}
check_file_text()
{
echo $1 >> $checklogs
is_file_text=$(file -i $1 | grep -w "text/plain")
if [ $check ]
then
head -n 10 "$1" >> $checklogs
fi
}
check_new_file()
{
while read -r line
do
is_old_file=$(grep -w $line -m 1 $1)
if [[ ! $is_old_file ]]
then
check_file_text $line
fi
done < $2
}
check_delete_file()
{
while read -r line
do
is_still_file=$(grep -w $line -m 1 $2)
if [[ ! $is_still_file ]]
then
echo $line >> $checklogs
fi
done < $1
}
create_file $checklogs
create_file $current_files
create_file $old_files
create_file $check_files
find $dir_etc -type f > $current_files
find $dir -type f -cmin -30 > $check_files
echo "[Log checketc - `date +%T` `date +%D`]" > $checklogs
echo "=== Danh sach file moi tao ===" >> $checklogs
check_new_file $old_files $check_files >> $checklogs
echo "=== Danh sach file sua doi ===" >> $checklogs
sudo find $dir_etc -mmin -30 >> $checklogs
echo "=== Danh sach file bi xoa ===" >> $checklogs
check_delete_file $old_files $current_files >> $checklogs
cat $current_files > $old_files
sendmail root@localhost < $checklogs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment