/tmp と /var/tmp の違い - しょぼんメモリ (´・ω・`)
ã®è¨äºãã¯ã¦ããããã®ã§ãtmpwatch ã«ã¤ãã¦ãã¡ã¢ã
tmpwatch ã®åä½
man ã«ããã¨ãtmpwatch ã¯æ¬¡ã®ããã«æ¯ãèãã
http://linux.die.net/man/8/tmpwatch
It does not follow symbolic links in the directories it's cleaning (even
if a symbolic link is given as its argument), will not switch
filesystems, skips lost+found directories owned by the root user, and
only removes empty directories, regular files, and symbolic links.
ã·ã³ããªãã¯ãªã³ã¯ã¯ãã©ããªãã
Owner ã root ã® lost+found ã¯å¦çããªãã
空ã®ãã£ã¬ã¯ããªãé常ã®ãã¡ã¤ã«ãã·ã³ããªãã¯ãªã³ã¯ãåé¤ããã
ï¼switch filesystems ã®æ¡ä»¶ãåãããªãã»ã»ã»CIFSãã¦ã³ããããã£ã¬ã¯ããªãªã©ã対象å¤ã«ãªãã®ãã¨æãã°ã対象ã¨ãªã£ã¦åé¤ããã模æ§ï¼
CentOS-6 ã® /etc/cron.daily/tmpwatch
$ cat /etc/cron.daily/tmpwatch #! /bin/sh flags=-umc /usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \ -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \ -X '/tmp/hsperfdata_*' 10d /tmp /usr/sbin/tmpwatch "$flags" 30d /var/tmp for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do if [ -d "$d" ]; then /usr/sbin/tmpwatch "$flags" -f 30d "$d" fi done
ä¸è¨ã§ä½¿ããã¦ããåãªãã·ã§ã³ã®æå³ã¯ä»¥ä¸ã®éãã
-uï¼æçµã¢ã¯ã»ã¹æå»
-mï¼æçµãã¡ã¤ã«å¤æ´æå»
-cï¼æçµi-nodeå¤æ´æå»
-xï¼æå®ãããã¹ã対象å¤ã¨ãã
-Xï¼æå®ãããã¿ã¼ã³ã«ããããããã¹ã対象å¤ã¨ãã
ãflags=-umcãã¨è¨è¼ããããtmpwatch ã« -umc ãªãã·ã§ã³ãä»å ãããã
-u, -m, -c ãåæã«æå®ãããã¨ãæ大å¤ï¼ææ°æå»ï¼ãå¤å®æ¡ä»¶ã«ãªãã
ãªããCentOS-6ãæå°ã¤ã³ã¹ãã¼ã«ããå ´åãtmpwatchãã¤ã³ã¹ãã¼ã«ããã¦ããªãã
yum ã§è¿½å ã¤ã³ã¹ãã¼ã«ããã°è¯ãã
tmpwatch ã®åä½ç¢ºèªæ¹æ³
ã³ãã³ãã¯ã/usr/sbin 以ä¸ã«ããã
æ¸å¼ã¯ã以ä¸ã®éãã
$ tmpwatch [option] [time] [dirs]
[time]ã«ã¯ãåé¤å¯¾è±¡ã¨ãªãé¾å¤ãæå®ããã
m/h/d ãæ°å¤ã®å¾ã«ä»ããã¨ãããããå/æ/æ¥ã§æå®ã§ããï¼çç¥ããã¨ããã©ã«ã㯠h ã«ãªãï¼
以ä¸ã®2ã¤ã¯åãã
$ tmpwatch 240 /tmp
$ tmpwatch 10d /tmp
tmpwatch ã³ãã³ãã§ãã¡ã¤ã«/ãã£ã¬ã¯ããªãåé¤ãããã試ãéã以ä¸ã®ãªãã·ã§ã³ãæå¹ã
-tï¼ãã¹ãã¢ã¼ãï¼å®éã«åé¤ã¯ããªãï¼
-vï¼è©³ç´°è¡¨ç¤º
é常ãã¡ã¤ã«ãåé¤ï¼ãã®ï¼ï¼
test ã¨æ¸ããã sample.txt ãä½æãããã¡ã¤ã«ã®æ´æ°æ¥æ/ã¢ã¯ã»ã¹æ¥æã2013/1/1ã«å¤æ´ããã
# echo 'test' > /tmp/twtest/sample.txt # touch -t 201301010000 /tmp/twtest/sample.txt # ls -l /tmp/twtest/sample.txt -rw-r--r-- 1 root root 5 1æ 1 00:00 2013 /tmp/twtest/sample.txt
-umc ãªãã·ã§ã³ã§ã¯åé¤å¯¾è±¡ã«ãªããªãã
touch ã³ãã³ãã§ã¯ã-c ã«ç¸å½ããi-nodeå¤æ´æå»ãå¤æ´ã§ããªãããã
# /usr/sbin/tmpwatch -umctv 10d /tmp/twtest/ grace period is 864000 seconds cleaning up directory /tmp/twtest
-um ã ãæå®ãã¦å®è¡ããã¨ãåé¤å¯¾è±¡ã«ãªãã
# /usr/sbin/tmpwatch -umtv 10d /tmp/twtest/ grace period is 864000 seconds cleaning up directory /tmp/twtest removing file /tmp/twtest/sample.txt
é常ãã¡ã¤ã«ãåé¤ï¼ãã®ï¼ï¼
test ã¨æ¸ããã sample.txt ãä½æãããã¡ã¤ã«ã®æ´æ°æ¥æ/ã¢ã¯ã»ã¹æ¥æã2013/1/1ã«å¤æ´ããã
# echo 'test' > /tmp/twtest/sample.txt # touch -t 201301010000 /tmp/twtest/sample.txt # ls -l /tmp/twtest/sample.txt -rw-r--r-- 1 root root 5 1æ 1 00:00 2013 /tmp/twtest/sample.txt
cat ã§ãã¡ã¤ã«ãéãã¦ã¢ã¯ã»ã¹æ¥æãæ´æ°ããã
# cat /tmp/twtest/sample.txt test
cat ã§ã¢ã¯ã»ã¹æ¥æãæ´æ°ãã¦ããããã-um ãªãã·ã§ã³ã§ã¯åé¤å¯¾è±¡ã«ãªããªãã
# /usr/sbin/tmpwatch -umtv 10d /tmp/twtest/ grace period is 864000 seconds cleaning up directory /tmp/twtest
-m ã ãæå®ãã¦å®è¡ããã¨ãåé¤å¯¾è±¡ã«ãªãã
# /usr/sbin/tmpwatch -mtv 10d /tmp/twtest/ grace period is 864000 seconds cleaning up directory /tmp/twtest removing file /tmp/twtest/sample.txt
ls -l ã§ãã¡ã¤ã«ã®ã¿ã¤ã ã¹ã¿ã³ãã確èªããtmpwatch ã§åé¤ãããäºãæå¾
ãã¦ãã¦ãåé¤ãããªãå ´åã¯ããæçµã¢ã¯ã»ã¹æ¥æãæ´æ°ããã¦ãããå¯è½æ§ãããã
ãtmpwatch æ¶ããªããã¨ããå ´åã¯ããã®è¾ºã確èªã
ls -l ã§ã¯ãã¢ã¯ã»ã¹æ¥æã¯è¡¨ç¤ºãããªãã
# ls -l /tmp/twtest/sample.txt -rw-r--r-- 1 root root 5 1æ 1 00:00 2013 /tmp/twtest/sample.txt
ã¢ã¯ã»ã¹æ¥æã表示ããã«ã¯ãls -lu ã¨ããã
# ls -lu /tmp/twtest/sample.txt -rw-r--r-- 1 root root 5 10æ 12 22:29 2014 /tmp/twtest/sample.txt
空ã®ãã£ã¬ã¯ããªãåé¤
空ã®ãã£ã¬ã¯ããªã¨ãä¸ã«ãã¡ã¤ã«ããããã£ã¬ã¯ããªãä½æãã¦ããã£ã¬ã¯ããªã®æ´æ°æ¥æã¨ã¢ã¯ã»ã¹æ¥æã2013/1/1ã«ããã
# mkdir /tmp/twtest/dummy-dir1 # mkdir /tmp/twtest/dummy-dir2 # touch /tmp/twtest/dummy-dir2/hoge.txt # touch -t 201301010000 /tmp/twtest/dummy-dir1 # touch -t 201301010000 /tmp/twtest/dummy-dir2 ï¼ããã§ls -l ããã¨ãã£ã¬ã¯ããªã«ã¢ã¯ã»ã¹æ¥æãæ´æ°ãããï¼ # ls -l /tmp/twtest/ åè¨ 8 drwxr-xr-x 2 root root 4096 1æ 1 00:00 2013 dummy-dir1/ drwxr-xr-x 2 root root 4096 1æ 1 00:00 2013 dummy-dir2/
æçµæ´æ°æ¥æã ãåé¤å¯¾è±¡ã®æ¡ä»¶ã¨ãã¦å®è¡ã
# /usr/sbin/tmpwatch -mtv 10d /tmp/twtest/ grace period is 864000 seconds cleaning up directory /tmp/twtest cleaning up directory /tmp/twtest/dummy-dir2 removing directory /tmp/twtest/dummy-dir2 if empty cleaning up directory /tmp/twtest/dummy-dir1 removing directory /tmp/twtest/dummy-dir1 if empty
-t ãªãã·ã§ã³ãå¤ãã¦å®è¡ããã¨ãä¸èº«ã空ã§ãã dummy-dir1 ã ããåé¤ãããã
Owner ã root ã® lost+found
Owner ã root ã® lost+found ãä½æããæ´æ°æ¥æã¨ã¢ã¯ã»ã¹æ¥æã2013/1/1ã«ããã
# mkdir /tmp/twtest/lost+found # touch -t 201301010000 /tmp/twtest/lost+found/ # /usr/sbin/tmpwatch -mtv 10d /tmp/twtest/ grace period is 864000 seconds cleaning up directory /tmp/twtest
Owner ã apacheï¼root 以å¤ã®ã¦ã¼ã¶ï¼ã«å¤æ´ãã¦è©¦ãã
# chown apache.apache /tmp/twtest/lost+found/ # touch -t 201301010000 /tmp/twtest/lost+found/ # /usr/sbin/tmpwatch -mtv 10d /tmp/twtest/ grace period is 864000 seconds cleaning up directory /tmp/twtest cleaning up directory /tmp/twtest/lost+found removing directory /tmp/twtest/lost+found if empty
Owner ã root ã§ãªãå ´åãlost+found ã¯ä»ã®ãã£ã¬ã¯ããªã¨åæ§ã«æ±ãããã¦åé¤å¯¾è±¡ã¨ãªãã
ã·ã³ããªãã¯ãªã³ã¯
sample.txt ãä½æãããã®ãã¡ã¤ã«ã¸ã®ã·ã³ããªãã¯ãªã³ã¯ slink ãä½æããã
æ´æ°æ¥æã¨ã¢ã¯ã»ã¹æ¥æããããã2013/1/1ã«å¤æ´ããã
# echo 'test' > /tmp/twtest/sample.txt # mkdir /tmp/twtest/dummy # ln -s /tmp/twtest/sample.txt /tmp/twtest/dummy/slink # touch -t 201301010000 /tmp/twtest/sample.txt # touch -t 201301010000 -h /tmp/twtest/dummy/slink
ã·ã³ããªãã¯ãªã³ã¯ã¯è¾¿ãããã·ã³ããªãã¯ãªã³ã¯ãã®ãã®ãåé¤ãããã
# /usr/sbin/tmpwatch -mtv 10d /tmp/twtest/dummy/ grace period is 864000 seconds cleaning up directory /tmp/twtest/dummy removing file /tmp/twtest/dummy/slink