Grep date pattern folder and zip -->delete

Hi All,

OS: Redhat Linux 7.5
Shell: Bash

I have some folder like this

2018-09-16
 2018-09-17
 2018-09-18
 2018-09-19

and so on...

Everyday one script create a folder with pattern YYYY-MM-DD (it will have so many sub directories files in it)

Now what I would like to achieve is a cron job should run every day 7 AM then it should check for previous day folder then zip it(tar.gz) with same name and delete the folder once tar is created successfully..

for example: if cron running on 2018-10-16 then it should find folder called 2018-10-15 --> tar it like tar -zcvf 2018-10-15.tar.gz 2018-10-15 --> then delete rm -rf of that 2018-10-15 folder

though i have clear cut of idea of step, finding difficult to list previousday folder by searching pattern...please help

We are not a coding service, but your date command does this for you:

# example using date command to find yesterday
date -d yesterday "+%Y-%m-%d"
2018-10-15
# do this make two files with known dates -one way to search
# start of yesterday:
 touch -t $(date -d yesterday "+%Y%m%d0000") start.tmp
# end of yesterday
 touch -t $(date -d yesterday "+%Y%m%d2359") end.tmp
# assume only one directory
 mydir=$(find /path/to/files  -type d ( -newer start.tmp -a  ! -newer end.tmp) )
# you need to code your tar solution here using the mydir variable here:
#
#
rm start.tmp end.tmp