for d in /tmp/aaa /tmp/bkk /tmp/bbb /tmp/ccc; do
if [ -d "$d" ]; then
/usr/bin/tmpwatch -f 720 "$d"
fi
done
would this remove the folders aaa bbb and ccc or their content?
THX a lot
Printable View
for d in /tmp/aaa /tmp/bkk /tmp/bbb /tmp/ccc; do
if [ -d "$d" ]; then
/usr/bin/tmpwatch -f 720 "$d"
fi
done
would this remove the folders aaa bbb and ccc or their content?
THX a lot
This script would remove the aaa, bbb, ccc and bkk directories in the /tmp directory, and the contents of aaa, bbb, ccc, and bkk, as long as these directories last access times were all more than 720 hours ago.
There are many reasons why "tmpwatch" will not delete directories.
Are you sure the "/tmp/bkk" directory and all of it's contained files have NOT been accessed within the past 720 hours? Accessing a file inside of a sub-directory of "/tmp/bkk" will not affect the access time of the "/tmp/bkk" directory, but it will ignore this contained file as it was last accessed within the past 720 hours, and so the "/tmp/bkk" directory will not be completely empty. If a directory is not completely empty first, it will not be deleted.
Another reason "tmpwatch" will avoid deleting a file is if there is a daemon process that has that file open. If the daemon process opened the file when it first started, and it started more than 720 hours ago, the access time of that file will be older than 720 hours ago, but "tmpwatch" will see that the file is "in-use" (still open in the daemon process) and so it will not delete that file.
One other possibility is that this directory contains a fifo (named pipe) or a special block/character device. You need to specify "tmpwatch -a -f" to delete "all" kinds of files (see the "tmpwatch" manpage).
Programs like "tmpwatch" need to be used very carefully -- misusing it can cause problems on your system weeks or months after you have initiated the command, long after you forgot about it. This makes tracking down problems extremely difficult! To avoid such problems, the "tmpwatch" program is designed to be as cautious as possible, deleting only simple files, empty directories, and symbolic links (without following the link), and only deleting files that are not currently opened by any users programs or daemon processes. It also will not delete other types of files unless you explicitly state on the command line that you want to delete fifos and block/character devices as well.
Be especially careful when using "tmpwatch -a -f" because like "sudo rm -Rf", it can cause serious damage.