Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Deleting old files

51 views
Skip to first unread message

contr...@gmail.com

unread,
Oct 8, 2012, 3:26:24 PM10/8/12
to
Hi,

Please help me to fix this script, I need delete old files (> 90 days)

#!/bin/ksh
set -x
SIZE=`df -P /home/devalias | grep -v Filesystem | awk '{ print $5 }' | tr -d %`
if [[ $SIZE -gt "10" ]]
then
/usr/bin/find /home/devalias/transfer* -type f -name "*.txt" -mtime +90 -exec rm -f {} \;
/usr/bin/find /home/devalias/transfer* -type f -name "*.cfm" -mtime +90 -exec rm -f {} \;
fi

Barry Margolin

unread,
Oct 8, 2012, 3:54:47 PM10/8/12
to
In article <06f77a1c-e04c-4551...@googlegroups.com>,
What's wrong with it? I can see ways to improve it, but I don't see any
serious problems with it.

You can combine the two finds into one, and run rm only once with all
the filenames, with:

/usr/bin/find /home/devalias/transfer* -type f \( -name '*.txt' -o -name
'*.cfm' \) -mtime +90 -exec rm -f {} +

And awk can do its own grepping and tr'ing:

SIZE=`df -P /home/devalias | awk '!/Filesystem/ {gsub("%", "", $5);
print $5}'`

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

contracer

unread,
Oct 9, 2012, 4:11:06 PM10/9/12
to
On 8 out, 16:54, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article <06f77a1c-e04c-4551...@googlegroups.com>,
> *** PLEASE post questions in newsgroups, not directly to me ***- Ocultar texto das mensagens anteriores -
>
> - Mostrar texto das mensagens anteriores -

I don´t know how, but find commands aren´t deleting old files...

Lem Novantotto

unread,
Oct 9, 2012, 4:22:05 PM10/9/12
to
contracer ha scritto:

> I don´t know how, but find commands aren´t deleting old files...

Please show the output of:

df -P /home/devalias | grep -v Filesystem | awk '{ print $5 }' | tr -d %

--
Bye, Lem
Ceterum censeo ISLAM esse delendum
_________________________________________________________________
Non sprecare i cicli idle della tua CPU, né quelli della tua GPU.
http://www.worldcommunitygrid.org/index.jsp
http://www.rnaworld.de/rnaworld/ http://home.edges-grid.eu/home/
http://www.gpugrid.net/

contracer

unread,
Oct 9, 2012, 4:29:22 PM10/9/12
to
On 9 out, 17:22, Lem Novantotto <Le...@Hotmail.com> wrote:
> contracer ha scritto:
>
> > I don´t know how, but find commands aren´t deleting old files...
>
> Please show the output of:
>
> df -P /home/devalias | grep -v Filesystem | awk '{ print $5 }' | tr -d %
>
> --
> Bye, Lem
> Ceterum censeo ISLAM esse delendum
> _________________________________________________________________
> Non sprecare i cicli idle della tua CPU, né quelli della tua GPU.
>          http://www.worldcommunitygrid.org/index.jsphttp://www.rnaworld.de/rnaworld/ http://home.edges-grid.eu/home/
>                    http://www.gpugrid.net/

12

Lem Novantotto

unread,
Oct 10, 2012, 3:35:36 AM10/10/12
to
contracer ha scritto:

> 12

Ok. And the output of:

/usr/bin/find /home/devalias/transfer* -type f -name "*.txt" -mtime +90

and of:

/usr/bin/find /home/devalias/transfer* -type f -name "*.cfm" -mtime +90

If find doesn't find any files, there are no files to delete.
If, on the contrary, some files are found, then:

- try using "-delete" instead of "-exec rm -f {} \;"
- try to delete one of them manually. What happens?
- has the user who runs this script the rights to delete these files?
- are these files immutable? Check with lsattr
- on which kind of filesystem are the files? Which options is it mounted with?
0 new messages