On 5/14/15, Craig Skinner <skin...@britvault.co.uk> wrote: [...] > Here's a diff of a modified /etc/daily /tmp purge portion: > > o replace test(1) '-L' with '-h' due to: > -L ... "Do not rely on its existence; use -h instead"
Interesting that FreeBSD[1] and MacOS X say the opposite. SUSv4 (one I have handy) has the exact same text for both options: True if pathname resolves to an existing directory entry for a symbolic link. False if pathname cannot be resolved, or if pathname resolves to an existing directory entry for a file that is not a symbolic link. If the final component of pathname is a symbolic link, that symbolic link is not followed --patrick [1] https://www.freebsd.org/cgi/man.cgi?query=test&apropos=0&sektion=0&manpath=FreeBSD+10.1-RELEASE&arch=default&format=html > o don't cd nor find(1) execdir, rather full path find. > o file find stage;- > o read found & skip directories for rm(1), > check found item isn't open with fstat. > o securely random pattern overwrite stale files. > o directory find stage;- > o find only empty directories for rmdir(1). > o 5 day stale directories. > o similarily order ignores of .X11-unix, .ICE-unix & portslocks. > o also purge stale;- > o pipes. > o sockets. > o dangling symlinks. > > > > Index: daily > =================================================================== > RCS file: /cvs/src/etc/daily,v > retrieving revision 1.83 > diff -u -p -r1.83 daily > --- daily 29 Apr 2015 00:10:44 -0000 1.83 > +++ daily 14 May 2015 15:53:00 -0000 > @@ -45,16 +45,32 @@ start_part "Running daily.local:" > run_script "daily.local" > > next_part "Removing scratch and junk files:" > -if [ -d /tmp -a ! -L /tmp ]; then > - cd /tmp && { > - find -x . \ > - \( -path './ssh-*' -o -path ./.X11-unix -o -path ./.ICE-unix \ > - -o -path ./portslocks -o -path './tmux-*' \) \ > - -prune -o -type f -atime +7 -execdir rm -f -- {} \; 2>/dev/null > - find -x . -type d -mtime +1 ! -path ./vi.recover ! -path ./.X11-unix \ > - ! -path ./.ICE-unix ! -path ./portslocks ! -name . \ > - -execdir rmdir -- {} \; >/dev/null 2>&1; } > -fi > +[[ -d /tmp && ! -h /tmp ]] && > +{ > + # stale files, not still held open: > + find -x /tmp \( -path '/tmp/ssh-*' -o -path '/tmp/tmux-*' \ > + -o -path /tmp/.X11-unix -o -path /tmp/.ICE-unix \ > + -o -path /tmp/portslocks \) -prune \ > + -o -type f -atime +7 | while read found > + do > + [[ -d ${found} ]] && continue > + fstat ${found} | grep -q ${found}$ || rm -P -- ${found} > + done > + > + # stale dangling symlinks: > + find -Lx /tmp -type l -ctime +14 \ > + -exec rm -- {} \; > + > + # stale pipes & sockets: > + find -x /tmp \( -type p -o -type s \) -ctime +40 \ > + -exec rm -- {} \; > + > + # stale directories: > + find -x /tmp -type d -mtime +5 -empty \ > + ! -name /tmp ! -path /tmp/vi.recover \ > + ! -path /tmp/.X11-unix ! -path /tmp/.ICE-unix \ > + ! -path /tmp/portslocks -exec rmdir -- {} \; > +} > > # Additional junk directory cleanup would go like this: > #if [ -d /scratch -a ! -L /scratch ]; then > > > Would it be a good idea to move the /scratch example out of the > /etc/daily script, and into daily(8), as an example for daily.local? > >