2013年3月8日 星期五

linux 刪除超大量檔案目錄

rm on a directory with millions of files
小心使用, 注意權限 





最常用的方法, 刪除整個目錄, 用 ls 無法顯示
rm -rf (dir)

檔案數超過一定數量
find <dir> -type f -exec rm {} \;

刪除超量(用find刪不掉), 目錄大小超過數百M, 甚至數十G, 一般是主機被駭才有機會 >_<
while [ true ]; do ls -Uf | head -n 10000 | xargs rm -f 2>/dev/null; done )

export i=0;
time ( while [ true ]; do
            ls -Uf | head -n 3 | grep -qF '.png' || break;
            ls -Uf | head -n 10000 | xargs rm -f 2>/dev/null;
            export i=$(($i+10000)); echo "$i...";
       done )




命令模式, 自動化將特定網頁轉換為PDF


wkhtmltopdf  http://code.google.com/p/wkhtmltopdf/
 簡單的命令工具, 將HTML轉換為 PDF
 適合將網管上HTML報表轉出


寫個Scripts加入排程, 在固定將資料轉出來(用EMAIL也不錯), 這樣就不用每天做苦工
儲存至 /var/www/html/ntop/Report', 依月份存放至各目錄


[root@cacti ~]# cat /var/www/html/ntop/html2pdf.sh
#!/bin/bash
fileName="ntop-`date +\%Y\%m\%d-\%H`.pdf"
dirName="Report-`date +\%Y\%m`"
savePath='/var/www/html/ntop/Report'
html2pdf='/var/www/html/ntop/wkhtmltopdf-amd64'

if [ ! -d "$savePath/$dirName" ]; then
/bin/mkdir -p "$savePath/$dirName"
fi

$html2pdf "http://ntop.host.ip:3000/sortDataIP.html" "$savePath/$dirName/$fileName"




CACTI 簡單增加一個自行開發頁面, 並加入一個頁簽連結

在PHP 程式碼增加
    include("../cacti/include/global.php");

判斷session 是否存在即可
  $_SESSION["sess_user_id"]
 
安裝 Superlinks 外掛套件, 主要功能快速增加頁簽的超連結
 
 

 在Console > External Links 增加一個頁簽 Session, 連結指向你的PHP程式
 


 按Session , 測試看看
 
 
 

Extreme XOS run pyton scripts

XOS run python scripts v15.7 or high 將交換器上的 IP & MAC 往syslog 丟, 簡單將IP資料保留下 ## 編緝Scripts # vi ip2syslog.py #!/usr/bin/python # ...