天天看點

Inotify 讓Linux FTP權限繼承

簡介:

FTP上傳檔案權限繼承有很多的方法能解決!最常用的是ACL,這裡我通過Inotify的實作

Inotify下載下傳位址: https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

編譯安裝

1、[root@localhost down]# wget --no-check-certificate https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz  \\  --no-check-certificate參數是支援https

2、[root@localhost down]# tar -zxf inotify-tools-3.14.tar.gz

3、[root@localhost inotify-tools-3.14]# ./configure

4、[root@localhost inotify-tools-3.14]# make ;make install

檢查

1、檢視是否支援核心

[root@localhost inotify-tools-3.14]# ll /proc/sys/fs/inotify

total 0

-rw-r--r-- 1 root root 0 Jul    9 19:43 max_queued_events

-rw-r--r-- 1 root root 0 Jul    9 19:43 max_user_instances

-rw-r--r-- 1 root root 0 Jul    9 19:43 max_user_watches

2、檢查軟體是安裝成功

[root@localhost inotify-tools-3.14]# ls /usr/local/bin/inotifywait        

/usr/local/bin/inotifywait

使用

1、我的FTP目錄是/var/www  使用如下指令監測運作下

/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format    '%T %w%f' -e modify,delete,create,attrib /var/www

2、OK,現在我們在/var/www建立一個testfile檔案。

[root@localhost www]# touch testfile

3、哈哈成功顯示出來資訊

[root@localhost inotify-tools-3.14]# /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format    '%T %w%f' -e modify,delete,create,attrib /var/www

09/07/11 20:01 /var/www/testfile

4、利用這個輸出,寫個SHELL自動繼承

#!/bin/bash

#inofp.sh

src=/var/www

/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format    '%T %w%f' \

-e modify,delete,create,attrib \

${src} \

| while read    file

                do

                                chmod -R 777 $file 2>/dev/null

                done

5、執行這個shell 

sh inofp.sh &>/dev/null &

6、去/var/www/建立個檔案夾和檔案試試 

[root@localhost www]# touch file

[root@localhost www]# mkdir directory

7、我腳本裡面設的權限是777 看看成功否

[root@localhost www]# ll

total 4

drwxrwxrwx 2 root root 4096 Jul    9 21:22 directory

-rwxrwxrwx 1 root root        0 Jul    9 21:25 file

8、OK成功全部777

繼續閱讀