FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 09-22-2010, 06:25 PM
Jochen Schulz
 
Default script (redirect output) to file and email

Pol Hallen:
>
> I try to redirect output of this script to file (using tee) and also send
> it to mail
>
> the script deletes files older than 150days:
>
> find /share/.trash/ -type f -atime +150 -exec rm -fr {} ;

- atime finds files *last accessed* 150 days ago. You probably need
mtime instead. I am not even sure whether running the script will
change the atime of all files in the directory and thus prevent
anything in it to be deleted. You should make sure that the filesystem
is not mounted with "relatime" or "noatime" as well when using atime.

- You are starting an rm process for every file to delete. You can end
the command with "+" instead of ";" to make find pass as many files
to rm as possible. If you delete many files that way, that may make a
big difference spped-wise.

- Do you want to have the list mailed as an attachment? -Then I would
just redirect the output to a file and use mutt's batch mode to send
the file (mutt -x -a $file).

- Otherwise, I would still redirect first and then send the mail as an
additional step:

find … > file
mail -s "$subject" $recipient < file

- If you insist:

find … | tee [-a] file | mail -s "$subject" $recipient

"tee -a" appends to "file", leaving out "-a" will overwrite "file".

J.
--
I wish I had been aware enough to enjoy my time as a toddler.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
 
Old 09-23-2010, 07:57 PM
Enrico Weigelt
 
Default script (redirect output) to file and email

* Jochen Schulz <ml@well-adjusted.de> schrieb:
> Pol Hallen:
> >
> > I try to redirect output of this script to file (using tee) and also send
> > it to mail
> >
> > the script deletes files older than 150days:
> >
> > find /share/.trash/ -type f -atime +150 -exec rm -fr {} ;
>
> - atime finds files *last accessed* 150 days ago. You probably need
> mtime instead.

Depends on the access patterns of these files. Maybe they're created
somewhen, but might be read later. In this case, -atime is correct.

> I am not even sure whether running the script will change the atime
> of all files in the directory and thus prevent anything in it to
> be deleted.

IMHO should not to. find does only directory scan and stat()'s, but
doesnt open() the files, so atime shouldn't be touched. (actually,
haven't checked yet).

> You should make sure that the filesystem is not mounted with
> "relatime" or "noatime" as well when using atime.

ACK. Note that this is done quite rarely, since it puts more load
onto the medium (metadata's touched each time a file's open()ed).
Maybe inotify is a better solution.

> - You are starting an rm process for every file to delete. You can end
> the command with "+" instead of ";" to make find pass as many files
> to rm as possible. If you delete many files that way, that may make a
> big difference spped-wise.

But you have to be careful that the command line doesnt get too long.
If you're really concerned about perfomance, you could use busybox
(with all commands compiled-in) as shell do write your script this way:


do_rm() {
while read FILE ; do rm -fr $FILE ; done
}

find /share/.trash/ -type f -atime +150 | do_rm


That will only require one or two fork()'s.

> - Do you want to have the list mailed as an attachment? -Then I would
> just redirect the output to a file and use mutt's batch mode to send
> the file (mutt -x -a $file).

If you have a local sendmail command, you could simply pipe it there.

(
echo "From: root@my.box.org"
echo "To: myself@foo.org"
echo "Subject: garbage collection output"
echo

find...
) | /usr/sbin/sendmail -t


cu
--
----------------------------------------------------------------------
Enrico Weigelt, metux IT service -- http://www.metux.de/

phone: +49 36207 519931 email: weigelt@metux.de
mobile: +49 151 27565287 icq: 210169427 skype: nekrad666
----------------------------------------------------------------------
Embedded-Linux / Portierung / Opensource-QM / Verteilte Systeme
----------------------------------------------------------------------


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20100923195734.GA20634@nibiru.local">http://lists.debian.org/20100923195734.GA20634@nibiru.local
 
Old 09-24-2010, 02:14 PM
Jochen Schulz
 
Default script (redirect output) to file and email

Enrico Weigelt:
> * Jochen Schulz <ml@well-adjusted.de> schrieb:
>
>> - You are starting an rm process for every file to delete. You can end
>> the command with "+" instead of ";" to make find pass as many files
>> to rm as possible. If you delete many files that way, that may make a
>> big difference spped-wise.
>
> But you have to be careful that the command line doesnt get too long.

No, find does that for you.

> If you're really concerned about perfomance, you could use busybox
> (with all commands compiled-in) as shell do write your script this way:
>
> do_rm() {
> while read FILE ; do rm -fr $FILE ; done
> }

That won't work with spaces in filenames. "find … -exec" or "find …
-print0 | xargs -0" are the best ways to do this. Apart from "find …
-delete" which I regularly forget.

J.
--
When driving at night I find the headlights of oncoming vehicles very
attractive.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
 
Old 09-24-2010, 08:03 PM
"Boyd Stephen Smith Jr."
 
Default script (redirect output) to file and email

In <20100924141439.GN15819@wasteland.homelinux.net> , Jochen Schulz wrote:
>Enrico Weigelt:
>> do_rm() {
>> while read FILE ; do rm -fr $FILE ; done
>> }
>
>That won't work with spaces in filenames. "find … -exec" or "find …
>-print0 | xargs -0" are the best ways to do this. Apart from "find …
>-delete" which I regularly forget.

Actually, that *will* work with spaces in the filenames[1], since the shell
built-in read doesn't stop until end of line. There are some other, even less
common, characters that can confuse read though: ', '"', and NL.

[1] At least with single space characters. Read might be sensitive to IFS/OFS
and merge runs of characters or translate all whitespace to space characters;
I'm not looking at the spec right now.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
 
Old 09-26-2010, 03:38 PM
Lorenzo Beretta
 
Default script (redirect output) to file and email

Il 24/09/2010 22:10, Boyd Stephen Smith Jr. ha scritto:

In<20100924141439.GN15819@wasteland.homelinux.net> , Jochen Schulz wrote:

Enrico Weigelt:

do_rm() {
while read FILE ; do rm -fr $FILE ; done
}


That won't work with spaces in filenames. "find … -exec" or "find …
-print0 | xargs -0" are the best ways to do this. Apart from "find …
-delete" which I regularly forget.


Actually, that *will* work with spaces in the filenames[1], since the shell
built-in read doesn't stop until end of line. There are some other, even less
common, characters that can confuse read though: ', '"', and NL.


No, it won't.
Look at "rm -fr $FILE" <-- $FILE isn't quoted ;D


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4c9f6907$0$18650$4fafbaef@reader3.news.tin.it">htt p://lists.debian.org/4c9f6907$0$18650$4fafbaef@reader3.news.tin.it
 
Old 09-26-2010, 09:50 PM
"Boyd Stephen Smith Jr."
 
Default script (redirect output) to file and email

In <4c9f6907$0$18650$4fafbaef@reader3.news.tin.it>, Lorenzo Beretta wrote:
>Il 24/09/2010 22:10, Boyd Stephen Smith Jr. ha scritto:
>> In<20100924141439.GN15819@wasteland.homelinux.net> , Jochen Schulz wrote:
>>> Enrico Weigelt:
>>>> do_rm() {
>>>>
>>>> while read FILE ; do rm -fr $FILE ; done
>>>>
>>>> }
>>>
>>> That won't work with spaces in filenames.
>>
>> Actually, that *will* work with spaces in the filenames[1], since the
>> shell built-in read doesn't stop until end of line.
>
>No, it won't.
>Look at "rm -fr $FILE" <-- $FILE isn't quoted ;D

I stand corrected.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
 
Old 09-27-2010, 06:27 AM
Mart Frauenlob
 
Default script (redirect output) to file and email

On 24.09.2010 22:03, Boyd Stephen Smith Jr. wrote:

In<20100924141439.GN15819@wasteland.homelinux.net> , Jochen Schulz wrote:

Enrico Weigelt:

do_rm() {
while read FILE ; do rm -fr $FILE ; done
}


That won't work with spaces in filenames. "find … -exec" or "find …
-print0 | xargs -0" are the best ways to do this. Apart from "find …
-delete" which I regularly forget.


Actually, that *will* work with spaces in the filenames[1], since the shell
built-in read doesn't stop until end of line. There are some other, even less
common, characters that can confuse read though: ', '"', and NL.

[1] At least with single space characters. Read might be sensitive to IFS/OFS
and merge runs of characters or translate all whitespace to space characters;
I'm not looking at the spec right now.


There might be some ppl finding this interesting:

eris:~# cat /tmp/tst
1, 2, foo bar
2, 3, bar foo
a b
a b
c d
d e

eris:~# while IFS= read -r; do echo "$REPLY"; done < /tmp/tst
1, 2, foo bar
2, 3, bar foo
a b
a b
c d
d e

eris:~# while read -r; do echo "$REPLY"; done < /tmp/tst
1, 2, foo bar
2, 3, bar foo
a b
a b
c d
d e

eris:~# while IFS= read -r foo; do echo "$foo"; done < /tmp/tst
1, 2, foo bar
2, 3, bar foo
a b
a b
c d
d e

eris:~# while read -r; do echo "$REPLY"; done < /tmp/tst
1, 2, foo bar
2, 3, bar foo
a b
a b
c d
d e

eris:~# while read -r foo; do echo "$foo"; done < /tmp/tst
1, 2, foo bar
2, 3, bar foo
a b
a b
c d
d e


GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

on debian lenny.



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: 4CA0394D.4080405@chello.at">http://lists.debian.org/4CA0394D.4080405@chello.at
 

Thread Tools




All times are GMT. The time now is 10:12 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org