Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting files from the directory and emailing them

Status
Not open for further replies.

HHG

Technical User
Nov 8, 2003
68
GB
Hi All,

Can anyone help with the following.

In a directory I have the following:-
-rw-rw-rw- 1 root other 17077 May 1 15:23 1790
-rw-rw-rw- 1 root other 31651 May 1 11:31 1789
-rw-rw-rw- 1 root other 17372 Apr 30 15:25 1788
-rw-rw-rw- 1 root other 24651 Apr 30 11:32 1787
-rw-rw-rw- 1 root other 24627 Apr 29 15:26 1786
-rw-rw-rw- 1 root other 32878 Apr 29 11:32 1785

The last field of each line is the file name e.g. 1790,1789

I am trying to write a script that will pick up all the files created each day and email them to an external email.

Any clues on how I might read the directory so that it only gives me a list of files created on the 1st May.

Any help would be very grate. Thanks in advance.
 
What have you tried so far and where in your code are you stuck ?
Tips:
man find
man touch

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi -
Not started it yet as I am stuck on stuck on how to actually ready the files and check the date is current date.

Any help would be grate. I can do the rest email etc..
Thanks
 
Have you read the 2 man pages I suggested you ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV I have used the find command with the -ctime option. All works find so far.
Thanks again
 
Hi again,

I'm a little stuck now on multiple attachment of files. I have done the following which works, but I need some bodytext. Any one suggest how I might include the body text please.

(for file in {directory path/*; do
uuencode ${file} $(basename ${file} )
done) | mailx -s "Subject of Title" {email addrress}



 
How about something like this...
Code:
#!/bin/ksh

TO=[ignore]someone@somewhere.com[/ignore]

(cat <<-MSG
Hi Everybody,

Here are a bunch of files from $(hostname) sent on $(date).

Please enjoy.
MSG
for FILE in /path/to/files/*
do
   uuencode ${FILE} $(basename ${FILE})
done
) | mailx -s "Files from $(hostname) as of $(date)" ${TO}
 
Sam - this works grate. Can you help with the find statement. For some reason the find statement I had before is not picking up files created today.

syntax I am using is:-

find . -ctime 0 -print

Now I am getting all of the files. Anyone have any ideas please. Thanks in advance.
 
Generally -ctime is not very useful, you may find -mtime (i.e. the last time the field was modified) more appropriate?

In any case I can't see why this would end up getting all of the files, can you show us the code around it?

Annihilannic.
 
Hi all - thanks for your time and help.

I have now managed to resolve it by using the command touch and find as below for anyone who wishes to find files that have been created on the current day :-

touch -t `date +%y%m%d0000` testfile

find . \( -name '*' \) -newer testfile -exec ls {} \;
 
What is the purpose of the "\( -name '*' \)"? That's not really needed as it will patch all names without you having to specify '*'.

The only thing I would add is maybe "-type f". Otherwise it will return directory names too, and that may not be what you want.
Code:
touch -t `date +%y%m%d0000` testfile

find . [b]-type f[/b] -newer testfile -exec ls {} \;

 
So putting it all together, this maybe?
Code:
#!/bin/ksh

TO=someone@somewhere.com

touch -t `date +%y%m%d0000` testfile

(cat <<-MSG
Hi Everybody,

Here are a bunch of files from $(hostname) sent on $(date).

Please enjoy.
MSG
find . -type f -newer testfile -print | while read for FILE
do
   uuencode ${FILE} $(basename ${FILE})
done
) | mailx -s "Files from $(hostname) as of $(date)" ${TO}

 
Oops! Make that while...
Code:
while read FILE
Take out the "for".

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top