I'm in a process of writing a script which checks the log folders, files and tails the log contents of the file for yesterday and today.
I have written the following code to check the folder existence for yesterday and today.
#!/bin/bash
YESTERDAY=$(date +%Y/%m/%d -d yesterday)
echo $YESTERDAY
TODAY=$(date +"%Y/%m/%d")
echo $TODAY
FOLDER="Alert1 Alert2 ..."
DATE="$YESTERDAY $TODAY"
#checks the log folder existence
for D in $FOLDER, E in $DATE; do
LOG="/usr/processing/logs/checks/$E/country/$D"
echo $LOG
test -d "$LOG" && echo "Located file @ $LOG"
done
I was expecting to get output like:
2022/10/09
2022/10/10
/usr/processing/logs/checks/2022/10/09/country/Alert1 #yesterday folder1
Located file @ /usr/processing/logs/checks/2022/10/09/country/Alert1
/usr/processing/logs/checks/2022/10/09/country/Alert2 #yesterday folder2
Located file @ /usr/processing/logs/checks/2022/10/09/country/Alert2
/usr/processing/logs/checks/2022/10/10/country/Alert1 #Today folder1
Located file @ /usr/processing/logs/checks/2022/10/10/country/Alert1
/usr/processing/logs/checks/2022/10/10/country/Alert2 #Today folder2
Located file @ /usr/processing/logs/checks/2022/10/10/country/Alert2
...but instead the actual output i got is:
2022/10/09
2022/10/10
/usr/processing/logs/checks//country/Alert1
/usr/processing/logs/checks//country/Alert2,
/usr/processing/logs/checks//country/E
/usr/processing/logs/checks//country/in
/usr/processing/logs/checks//country/2022/10/09
/usr/processing/logs/checks//country/2022/10/10
I'm actually trying to use two variables (i.e. $FOLDER and $DATE )in a single for
loop but unfortunately the above loop with variables clearly doesn't work as expected. The variables reassigned in the for
loop gives away an output which doesn't iterate expected statement/directory path with corresponding variable values. Hopefully someone can help me resolve this.
Thanks!