Rm sessiondata from crontab

I’m trying to get find with -exec to work … and I’m not getting any
luck

Here’s the cmdline from the RT docs, for the -exec , syntax looks great
from the man pages, but I keep getting “/usr/bin/find: missing argument
to `-exec’”.

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
/bin/rm ‘{}’ ;

Any ideas? I wouldn’t be surprised that RedHat 7.2 would use some sort
of their own /usr/bin/find, but I want to make sure if I’m not missing
something…

Thanks
Kris

|+ Here’s the cmdline from the RT docs, for the -exec , syntax looks great
|+ from the man pages, but I keep getting “/usr/bin/find: missing argument
|+ to `-exec’”.
|+
|+ /usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
|+ /bin/rm ‘{}’ ;

Just to clarify, the /bin/rm ‘{}’ is on the same line as -exec, correct?

Just at first glance, I would say put a backslash before the semicolon
to escape it. Otherwise, the shell will probably interpret the
semicolon, but you want ‘find’ to interpret the semicolon as closing
the -exec parameter.

Matt

Darrin Walton writes:

Kristopher Lalletti escribi�:

I’m trying to get find with -exec to work … and I’m not getting any
luck

Here’s the cmdline from the RT docs, for the -exec , syntax looks great
from the man pages, but I keep getting “/usr/bin/find: missing argument
to `-exec’”.

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
/bin/rm ‘{}’ ;

Any ideas? I wouldn’t be surprised that RedHat 7.2 would use some sort
of their own /usr/bin/find, but I want to make sure if I’m not missing
something…

You miss the backslash at the end.
The correct is:
/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
/bin/rm ‘{}’ ;

man find for more information.

Greetings
Adrian Galindo

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
/bin/rm ‘{}’ ;

Can someone with access update the installation guide at
http://fsck.com/rtfm/article.html?id=2#100
to include the backlash?

|+ Can someone with access update the installation guide at
|+ http://fsck.com/rtfm/article.html?id=2#100
|+ to include the backlash?

FYI, the README file that is included with RT is correct.

Hi,

Also, for efficiency/reliability purposes you might want to try:

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -print |
/usr/bin/xargs -i /bin/rm ‘{}’

IIRC, -exec is kind of a resource hog. xargs gets around limits on
number of arguments because -exec can crap out if the number of
files returned is large. xargs is pretty useful but not well advertised.

hth,

– BobOn 18 Jan 2002, at 11:49, Adrian Galindo wrote:

Kristopher Lalletti escribió:

I’m trying to get find with -exec to work … and I’m not getting any
luck

Here’s the cmdline from the RT docs, for the -exec , syntax looks
great from the man pages, but I keep getting “/usr/bin/find: missing
argument to `-exec’”.

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
/bin/rm ‘{}’ ;

Any ideas? I wouldn’t be surprised that RedHat 7.2 would use some
sort of their own /usr/bin/find, but I want to make sure if I’m not
missing something…

You miss the backslash at the end.
The correct is:
/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
/bin/rm ‘{}’ ;

man find for more information.

Greetings
Adrian Galindo


rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Hi,

You are right that -exec is a resource hog but for the wrong reason.
-exec gets passed a single file and so creates a separate /bin/rm process
for every file encountered.

Unfortunately, your example is just as inefficient as using -exec (at least
for GNU find on my Slackware system). The -i switch explicitly says to
replace the braces with the input and defaults to ONE line at a time. Since
find produces output one filename to a line, your xargs is calling /bin/rm
for
each file, just like -exec would. If you call xargs without the -i switch
like this,

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -print |
/usr/bin/xargs /bin/rm

xargs will accrue as much input as possible that will fit on a single
command line and pass that to /bin/rm in one swell foop. Voila, one call
to /bin/rm to delete many files. HTH.

ttfn,
kevin

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -print |
/usr/bin/xargs /bin/rm

xargs will accrue as much input as possible that will fit on a single
command line and pass that to /bin/rm in one swell foop. Voila, one call
to /bin/rm to delete many files. HTH.

Just a general observation, when using find and xargs together, you may
run into files with spaces or other weird characters in them. Not a
problem in this specific case, however it is generally better to:

find directory -type f (various conditions) -print0 |
xargs -0 -r rm

The ‘-print0’ to find and ‘-0’ to xargs are ‘print results terminated with
the NULL character’ and ‘input arguments are terminated with the NULL
character’. Otherwise, if
files-with-spaces-and-other-shell-seperation-characters are present, then
xargs will bomb out in an interesting fashion.

The ‘-r’ option simply disables the running of your command (rm) if there
is no input from find (no matching files). Otherwise, rm will print a
highly-helpful message of ‘too few arguments’ or something similar.

One you have run your routine cleanup command a few times, put it into the
appropriate crontab (NOT ROOT), and remember to pipe both the stdout and
stderr to /dev/null, unless you really want to see what a known command
produces each time it runs.

Bruce.

Thank-you for watching Useful Little Known Unix Tricks; Spotlight on
Xargs. Next week on the show, we will be demonstrating how little
awk(ward) programs can ease your routine script maintainence.

Done. Just so you know, I do read things here from time to time… :slight_smile:

At 18:09 18/01/02, Peter E. Popovich wrote:

/usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec
/bin/rm ‘{}’ ;

Can someone with access update the installation guide at
http://fsck.com/rtfm/article.html?id=2#100
to include the backlash?


rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Feargal Reilly,
Systems Administrator,
The CIA.

I’m trying to get find with -exec to work … and I’m not getting any
luck

Thanks
Kris

Hi,

I had the same problem. My solution:

Change through crontab -e :

#0 * * * * find /opt/rt2/WebRT/sessiondata -type f -amin +600 -exec rm ‘{}’
;
0 * * * * /opt/rt2/bin/rtcron

Write a small script “rtcron” :

Every hour, delete session files and lockfiles that haven’t

been touched in 10 hours

AGEINFO=“+600” # purge files after 10 hours untouched

CAT=“/bin/cat”
RM=“/bin/rm”
RM=“$RM -f”

JUNK=/tmp/rtjunk$$ # temp file used for file listing

trap “$RM $JUNK; exit 1” 0 1 2 15
find /opt/rt2/WebRT/sessiondata -type f -amin $AGEINFO -print >$JUNK

if [ -s $JUNK ]; then
for i in $CAT $JUNK; do

echo " $i"

     $RM $i

done
fi

That is all. It works.

Wojtek