>Are general linux questions off-topic here? I'm trying to automate some
>tasks, one of which is detailed below:

Many people around here (myself included) enjoy solving these sorts of
problems.

>With the following commands in a shell script, I want to search for files
>that have been modified on the current date and have the output mailed to
>me, probably will run this as a cron job, I have that covered though.

Hold it right there. You don't even need grep; what you need is the find(1)
command. This command is a generalised filesystem tranverser, holder of the
most bizarre syntax in the Unix menagerie. But's it's also damned useful
once mastered.

        find / -mtime 1 -print

will search the filesystem starting at /, and recursing into all
subdirectories. the command will print out every single file (with its
fully-qualified pathname) having a modified time of one day. It goes without
saying that the process needs to be run as root in order to get past some
directories that are blocked to joe user.

>date +'"%b %-d"'>file.txt
>
>date string above dumps this to file.txt: "Apr  8"
>
>ls -laR /home/higginbo | grep -ffile.txt | mail higginbo

This won't work at all, although for future reference:

        ls -laR /home/higginbo | grep `cat ffile.txt` | mail higginbo

will do what you want. This is referred to as backticking. Consider it as a
macro substitution on grep's command line that involves running another
process.

>grep should be reading standard input from the ls command, using the string
>in file.txt as an argument, and then mailing the results to me. I get
>nothing. I think the problem is with the syntax I am using with grep.
>Anyone see anything wrong?

Returning to the find example above, if all you want is the name of the file
then just pipe it to mail:

        find /home/higginbo -mtime 1 -print | mail -s 'Modified file list'

If you want ls's output, then you should pipe the output to xargs, which in
turn will launch the minimal number of ls processes required. There is an
inefficient alternative that involves launching one ls process per file that
I am not even going to discuss. You're better off not knowing it, and you'll
impress your friends.

        find /home/higginbo -mtime 1 -print | xargs ls -la |
                mail -s 'Modified file list'

(All on one line).

Read up on find and xargs in the man pages.
DL
--
        affairs and are crunchy Do for good in ketchup.
        meddle not of the taste with wizards, you


-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com/RedHat-FAQ /RedHat-Errata /RedHat-Tips /mailing-lists
         To unsubscribe: mail [EMAIL PROTECTED] with 
                       "unsubscribe" as the Subject.

Reply via email to