I've a file named 62810501601420200502.swt1
and in the end I have date in this format 20200502 and in front of it is just a random number which changes (dynamic). What I want is that I want to read only the date of the file and create log out of it through a shell script.
For example if today is 20200502 then I create log which says File found in the server, else if the file is not found then it simply says file not found on the server.
In the below code I have a file with a fixed name in front so I was able to create logs and other stuff.
But now my file name can be changed but date position is fixed and also the filename length is fixed.
#!/bin/sh
###############################################
PU=$(date +%d-%m-%Y)
Date=$(date +%Y-%m-%d)
###############################################
urban="/Path/of/file/PAYMENT_$PU.csv"
###############################################
if [ -f "$urban" ]; then
echo "[$PU] $urban file exist" >> /Mail_Scripts/mail.log
else
echo "[$Date] $urban file does not exist" >> /Scripts/mail.log
echo "$Date,CCB,PAYMENT_$PU.csv,IP" >> /Scripts/iles.csv
fi
###############################################
Any suggestions or solution?
date +%Y-%m-%d
does not output something like20200502
.PAYMENT_
is not a random number.