Article 5GRQP Script to alert if no new file created in a directory.

Script to alert if no new file created in a directory.

by
linuxdb@gmail.com
from LinuxQuestions.org on (#5GRQP)
I would like to get an alert whenever there is no new file or directory created over a particular time i.e. for last one hour or a day

Sript 1 is listing the directories declared in script. Taking it little further in script 2 list directories like /u01/log/2021-02. Need Help in script 2 it is failing.

Script 1

#!/bin/bash
arr=(/u01/log/*)
for ((i=0; i < ${#arr[@]}; i++)); do
ls -ld "${arr[$i]}"
done

Success: output -->
/u01/log/log-server1
....
.....
so on..

script 2

#set -xv
#!/bin/bash
MON=date '+%m'
DAY=date '+%d'
YEAR=date '+%Y'
YEAR-MON=date '+%Y-%m'
arr=(/u01/log/*)
for ((i=0; i < ${#arr[@]}; i++)); do
FILE="${arr[$i]}/${YEAR-MON}"
ls -ld $FILE
done

Error: list.sh: line 4: +%m: command not found
list.sh: line 5: +%d: command not found
list.sh: line 6: +%Y: command not found
list.sh: line 7: YEAR-MON=date: command not found
list.sh: line 13: MON: command not found

Once this is resolved it should email alert if no new files created in /u01/log/YEAR-MON

Thanks
Javeedlatest?d=yIl2AUoC8zA latest?i=7etF9VivMWQ:io_ELBUscKE:F7zBnMy latest?i=7etF9VivMWQ:io_ELBUscKE:V_sGLiP latest?d=qj6IDK7rITs latest?i=7etF9VivMWQ:io_ELBUscKE:gIN9vFw7etF9VivMWQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments