Jim Reimer wrote:
>
> Given a file that contains a line indicating the date and
> time the file expires, in the form:
>
> Expires:200005281430;Remove:200005281430;991272
>
> (this example is 28 May, 2000 @ 1430Z)
>
> can one easily determine with a shell script if the file
> has indeed expired, and then delete it? I realize this
> would be a trivial task using C or Perl, but what about
> the standard command-line tools like grep, sed, and so on?
>
<snip>
Just as a starter:
1> #!/bin/bash
2> # echos all names of files that have expired
3> today=$(date +'%Y%m%d')
4> for i in "$@"; do
5> grep expires "$i" | \
6> while read; do
7> result=$(expr match "$REPLY" '[^0-9]*\([0-9]+\)[^0-9]*')
8> [ "$result" ] || continue
9> [ "$result" -lt "$today" ] && echo $i
0> done
1> done | uniq
this lacks time{,zones} and probably fails on files with multiple
numerical values on lines that contain 'expires'. But you can always
adjust the eval regexp (l.7) and the date timeformat (l.3) to fit your
needs.
Marc
--
Marc Mutz <[EMAIL PROTECTED]> http://marc.mutz.com/Encryption-HOWTO/
University of Bielefeld, Dep. of Mathematics / Dep. of Physics
PGP-keyID's: 0xd46ce9ab (RSA), 0x7ae55b9e (DSS/DH)
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs