richen
11th August 2004, 10:44
Can anybody help me with the following problem?

I have a directory in Unix with contains files starting with HRA_ERR. Followed by date en sequence number

Example HRA_ERR.081104123456

I want to find the file(s) with contains the present date. When I have found this file I want to mail to an user.

norwim
11th August 2004, 11:30
grep -l 2004-08-11 HRA-ERR* should give youe the names of all files with filename HRA_ERR'whatsoever' containing the string '2004-08-11'.
Please check before whether the date ist written that way.
Once you identified the files concerned, ftp them to a windowsbox and attach them to a mail.

hth

Norbert

richen
11th August 2004, 12:08
I have tried grep -l but it doesn't work, It gives no results. Is there another way? Maybe with a find commando?

The system gives the date as Aug 11

NPRao
13th August 2004, 03:53
Try this -

DATE=`date -u +%C%y%m%d`
for fname in `ls *${DATE}`
do
mailx -s "Testing" bsp@baan.com < $fname
done

You can explore the different options in the date command based on your filenames.

kbartelds
13th August 2004, 09:58
To keep it simple: create subdirectory send_files

for fname in `ls |grep -v send_files`
do
mailx -s "Testing" bsp@baan.com < $fname
mv $fname send_files
done

Regards,
Klaas

richen
13th August 2004, 14:50
I tried to use for fname in 'ls | grep - v send_files'
(natural I'm in the right directory)

But i got a message back from the system;

ls |grep -v send_files: cannot open

What went wrong here?

when i use ls | grep - v send_files in the directory I see a result.

NPRao
13th August 2004, 20:14
You can also use the find command -

$ find $yourpath -name "*08122004" -type f -exec /bin/mailx -s "found files" < {} \;

You can look up on the proper syntax and different options from the man pages.

dnnslbrwn
17th August 2004, 21:31
Richen,

Your problem is your quotes around (ls | grep -v send_files). They should be back-quotes and I am guessing that you just used a normal single quote. On my keyboard, the back-quote is in the upper left corner.

Why a back quote and why does it matter? In UNIX, the back quote is a way of telling the system to execute what is inside the back quotes and pass the results to the for statement.

As a separate note, there is no space between the "-" and the "v" in the grep command.

Cheers,

-Dennis