Extract specific date in a directory and send output through email

Extract specific date in a directory and send output through email

Post by Dave » Sun, 15 Aug 2004 12:12:11



Greetings folks..this is my first post and i hope i'm doing this
correctly.

Here is my problem:

ls -lrt /bs/processing/* >> jess1.txt

This part of my script is fine.  It pulls all of the data in the
directory and places it in a txt file.

However, i want to pull only the current dates data (IE:  Today)

I thought i could use this but its not working:

dateM='date | cut -c 5-10'
cat jess1.txt ls -lartR |grep "$dateM" >> jess2.txt

These commands don't pull anything.

Please help.

 
 
 

Extract specific date in a directory and send output through email

Post by SINNE » Sun, 15 Aug 2004 12:52:18


* DaveL wrote in comp.unix.shell:

Quote:> Greetings folks..this is my first post and i hope i'm doing this
> correctly.
> Here is my problem:
> ls -lrt /bs/processing/* >> jess1.txt
> This part of my script is fine.  It pulls all of the data in the
> directory and places it in a txt file.
> However, i want to pull only the current dates data (IE:  Today)
> I thought i could use this but its not working:
> dateM='date | cut -c 5-10'
> cat jess1.txt ls -lartR |grep "$dateM" >> jess2.txt
> These commands don't pull anything.
> Please help.

I cant believe I figured this out, Thanks ;)

you need to use the back tick ` rather then the quote '

dateM=`date | cut -c 5-10`

should do it for you, it did for me :)

With the quote "echo $test" returned the string rather then the result.
--
David                 | AGM Favorites - http://tinyurl.com/loec
The most delightful day after the one on which you buy a cottage in
the country is the one on which you resell it.
                -- J. Brecheux

 
 
 

Extract specific date in a directory and send output through email

Post by Chris F.A. Johnso » Mon, 16 Aug 2004 06:30:29



> Greetings folks..this is my first post and i hope i'm doing this
> correctly.

   So far, so good.

Quote:> Here is my problem:

> ls -lrt /bs/processing/* >> jess1.txt

    Are you sure this is what you want? This will list the contents of
    subdirectories, if any, as well as the contents of /bs/processing.

    If you don't want that, add the -d option.

Quote:> This part of my script is fine.  It pulls all of the data in the
> directory and places it in a txt file.

> However, i want to pull only the current dates data (IE:  Today)

> I thought i could use this but its not working:

> dateM='date | cut -c 5-10'

    Two things: first, to get the output of a command, use backticks,
    not apostrophes:

dateM=`date | cut -c 5-10`

    Second, you can get the portions directly with the date command.
    There's no need for cut (although, if you're using a Bourne shell,
    it may be the quickest way):

    If you have GNU date:

dateM=`date "+%h %_d"`

    Otherwise (assumes a POSIX shell):

eval `date "+month=%h day=%d"`
case $day in
     0?) day=" ${day#?}" ;;
esac
dateM="$month $day"

Quote:> cat jess1.txt ls -lartR |grep "$dateM" >> jess2.txt

    You can do it without a temporary file:

ls -d -lrt /bs/processing/* | grep "$dateM" > FILE.txt

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License