Trying to find how to regularly find any file generated 1 day ago and the name has pattern "performance-team(A/B/C)-(yesterday's date)". And then email it to certain mail-address from Tuesday to Sunday at 2 am?

My current script "testScript1.sh" is as follows:

#do not know how to include a day before date and team names : A,B or C
arr=($(find /root/Desktop/fileName -maxdepth 1 -name "performance-team*.txt" -mtime 0))

for i in "${arr[@]}"
    echo -e "to:email@email.com\nSubject:performance latest\n"|(cat - && uuencode $i)|/usr/sbin/ssmtp email@email.com

In crontab my command is

0 2 * * 2-7 /bin/sh /root/Desktop/fileName/testScript1.sh

Above testScript1.sh script is not giving me exact thing. I also cannot run it regularly in crontab. Please help.

  • What did you try? – heemayl Oct 17 '16 at 5:04

use -d option of date e.g.

date -d yesterday

for instance

> date
Mon Oct 17 07:36:10 CEST 2016
> date -d yesterday
Sun Oct 16 07:36:17 CEST 2016

you can also use +% format

date -d yesterday +%A-%d-%B


see man date

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.