2012年7月18日 星期三

Get ip username login root shell script

vi  /root/.bashrc



# which mail addres to send?
email='xxx@xxx.com.tw,root_check@xxx.com.tw'

#get user information
ipaddr=`who am i | awk '{print $6}' | cut -d '(' -f2 | cut -d ')' -f1`
tty=`who am i | awk '{print $2}'`
username=`ps aux | grep "$tty" | grep sshd | awk '{print $12}' | head -n1 | cut -d '@' -f1`

#check macaddr
ping "$ipaddr" -c1 &> /dev/null
macaddr=`arp -a $ipaddr | awk '{print $4}'`

#input from whitch interface
interface=`arp -a $ipaddr | awk '{print $7}'`

#check if can't receive macadr
if [ "$macaddr" == 'entries' ]; then
        macaddr="can't find macaddr in arp"
fi

if [ "$interface" == 'found.' ]; then
        interface="can't find interface in arp"
fi

#send mail now
echo -e "
  Somebody changing identity to [ root ] on `hostname`!! \n
  username:       $username \r
  ipaddr:         $ipaddr \r
  macaddr:        $macaddr \r
  interface:      $interface \r
  console:        $tty \r
  date:           `date` \n" | mail -s "Somebody changing identity to SUPERUSER on `hostname`!!" $email
shopt -s histappend
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"


httpd-2.2.21 + tomcat-connectors + modsecurity 2.5.13 參數設定


1.install httpd
./configure --prefix=/opt/httpd/ --enable-so --enable-rewrite --enable-deflate --enable-headers --enable-ssl --enable-info --enable-expires --enable-proxy --enable-proxy-http --enable-unique-id --enable-logio && make && make install

2. instal modsecurity 2.5.13
./configure --with-apxs=/opt/httpd/bin/apxs --with-apr=/resource/httpd-2.2.21/srclib/apr/ --with-apu=/resource/httpd-2.2.21/srclib/apr-util/ && make && make install

3.  install tomcat-connectors
./configure --with-apxs=/opt/httpd/bin/apxs && make && make install


tomcat 設定另在寫~

正規表示式 Regular Expression

完全只是會忘記@@~所以寫在這~給自己看

資料來源


字元說明簡單範例
\避開特殊字元/A\*/ 可用於比對 "A*",其中 * 是一個特殊字元,為避開其特殊意義,所以必須加上 "\"
^比對輸入列的啟始位置/^A/ 可比對 "Abcd" 中的 "A",但不可比對 "aAb"
$比對輸入列的結束位置/A$/ 可比對 "bcdA" 中的 "A",但不可比對 "aAb"
*比對前一個字元零次或更多次/bo*/ 可比對 "Good booook" 中的 "booo",亦可比對 "Good bk" 中的 "b"
+比對前一個字元一次或更多次,等效於 {1,}/a+/ 可比對 "candy" 中的 "a",但不可比對 "caaandy"
?比對前一個字元零次或一次/e?le?/ 可比對 "angel" 中的 "el",但不可比對 "angle"
.比對任何一個字元(但換行符號不算)/.n/ 可比對 "nay, an apple is on the tree" 中的 "an" 和 "on",但不可比對 "nay"
(x)比對 x 並將符合的部分存入一個變數/(a*) and (b*)/ 可比對 "aaa and bb" 中的 "aaa" 和 "bb",並將這兩個比對得到的字串設定至變數 RegExp.$1 和 RegExp.$2。
xy比對 x 或 y/a*b*/g 可比對 "aaa and bb" 中的 "aaa" 和 "bb"
{n}比對前一個字元 n 次,n 為一個正整數/a{3}/ 可比對 "lllaaalaa" 其中的 "aaa" 但不可比對 "aa"
{n,}比對前一個字元至少 n 次,n 為一個正整數/a{3,}/ 可比對 "aa aaa aaaa" 其中的 "aaa" 及 "aaaa" 但不可比對 "aa"
{n,m}比對前一個字元至少 n 次,至多 m 次,m、n 均為正整數/a{3,4}/ 可比對 "aa aaa aaaa aaaaa" 其中的 "aaa" 及 "aaaa" 但不可比對 "aa" 及 "aaaaa"
[xyz]比對中括弧內的任一個字元/[ecm]/ 可比對 "welcome" 中的 "e" 或 "c" 或 "m"
[^xyz]比對不在中括弧內出現的任一個字元/[^ecm]/ 可比對 "welcome" 中的 "w" "l" "o" 可見出其與 [xyz] 功能相反 同時請同學也注意 /^/ 與 [^] 之間功能的不同
[\b]比對退位字元(Backspace character)可以比對一個 backspace ,也請注意 [\b] 與 \b 之間的差別
\b比對英文字的邊界,例如空格例如 /\bn\w/ 可以比對 "noonday" 中的 'no' ;
/\wy\b/ 可比對 "possibly yesterday." 中的 'ly'
\B比對非「英文字的邊界」例如, /\w\Bn/ 可以比對 "noonday" 中的 'on' ,
另外 /y\B\w/ 可以比對 "possibly yesterday." 中的 'ye'
\cX比對控制字元(Control character),其中 X 是一個控制字元/\cM/ 可以比對 一個字串中的 control-M
\d比對任一個數字,等效於 [0-9]/[\d]/ 可比對 由 "0" 至 "9" 的任一數字 但其餘如字母等就不可比對
\D比對任一個非數字,等效於 [^0-9]/[\D]/ 可比對 "w" "a"... 但不可比對如 "7" "1" 等數字
\f比對 form-feed若是在文字中有發生 "換頁" 的行為 則可以比對成功
\n比對換行符號若是在文字中有發生 "換行" 的行為 則可以比對成功
\r比對 carriage return
\s比對任一個空白字元(White space character),等效於 [ \f\n\r\t\v]/\s\w*/ 可比對 "A b" 中的 "b"
\S比對任一個非空白字元,等效於 [^ \f\n\r\t\v]/\S/\w* 可比對 "A b" 中的 "A"
\t比對定位字元(Tab)
\v比對垂直定位字元(Vertical tab)
\w比對數字字母字元(Alphanumerical characters)或底線字母("_"),等效於 [A-Za-z0-9_]/\w/ 可比對 ".A _!9" 中的 "A" "_" "9"
\W比對非「數字字母字元或底線字母」,等效於 [^A-Za-z0-9_]/\W/ 可比對 ".A _!9" 中的 "." " " "!" 可見出其與 \w 功能恰好相反
\ooctal比對八進位,其中octal是八進位數目/\oocetal123/ 可比對 與 八進位的ASCII中 "123" 所相對應的字元值
\xhex比對十六進位,其中hex是十六進位數目/\xhex38/ 可比對 與 16進位的ASCII中 "38" 所相對應的字元



通用式說明及範例比對不成立之字串
/a/含字母 "a" 的字串,例如 "ab", "bac", "cba""xyz"
/a./含字母 "a" 以及其後任一個字元的字串,例如 "ab", "bac"(若要比對.,請使用 \.)"a", "ba"
/^xy/以 "xy" 開始的字串,例如 "xyz", "xyab"(若要比對 ^,請使用 \^)"axy", "bxy"
/xy$/以 "xy" 結尾的字串,例如 "axy", "abxy"以 "xy" 結尾的字串,例如 "axy", "abxy" (若要比對 $,請使用 \$)"xya", "xyb"
/[13579]/包含 "1" 或 "3" 或 "5" 或 "7" 或 "9" 的字串,例如:"a3b", "1xy""y2k"
/[0-9]/含數字之字串不含數字之字串
/[a-z0-9]/含數字或小寫字母之字串不含數字及小寫字母之字串
/[a-zA-Z0-9]/含數字或字母之字串不含數字及字母之字串
/b[aeiou]t/"bat", "bet", "bit", "bot", "but""bxt", "bzt"
/[^0-9]/不含數字之字串(若要比對 ^,請使用 \^)含數字之字串
/[^aeiouAEIOU]/不含母音之字串(若要比對 ^,請使用 \^)含母音之字串
/[^\^]/不含 "^" 之字串,例如 "xyz", "abc""xy^", "a^bc"


通用表示法的特定字元說明等效的通用表示法
\d數字[0-9]
\D非數字[^0-9]
\w數字、字母、底線[a-zA-Z0-9_]
\W非 \w[^a-zA-Z0-9_]
\s空白字元[ \r\t\n\f]
\S非空白字元[^ \r\t\n\f]
通用表示法說明
/a?/零或一個 a(若要比對? 字元,請使用 \?)
/a+/一或多個 a(若要比對+ 字元,請使用 \+)
/a*/零或多個 a(若要比對* 字元,請使用 \*)
/a{4}/四個 a
/a{5,10}/五至十個 a
/a{5,}/至少五個 a
/a{,3}/至多三個 a
/a.{5}b/a 和 b中間夾五個(非換行)字元

Linux 在vim 中 如何區塊編輯

Linux 在vim 中 如何區塊編輯~


1. ctrl + v  後 選取 要編輯的區塊

2. 建入 大寫I

3. 輸入要編輯的文字

4 按ESC 離開

5 最後記得存檔...XD