shell小指令碼4

2021-10-02 03:17:18 字數 2300 閱讀 9247

1、編寫指令碼selinux.sh,實現開啟或禁用selinux功能

selinux有三種模式

enforcing:強制模式。代表selinux在執行,且已經開始限制domain

/type之間的驗證關係

permissive:寬容模式。不會限制domain

/type之間的驗證關係,即使驗證不正確,程序仍可以對檔案進行操作。不過如果驗證不正確會發出警告

disabled:關閉模式。selinux並沒有實際執行

#!/bin/bash

#2020.1

.11file

="/etc/selinux/config"

echo

"select

install

1enforcing

強制模式

2permissive

寬容模式

3disabled

關閉模式

4exit退出"

sleep

0.1read

-p"please input 1,2,3,4: "

idif[[

$id==1

]];then

sed-ri

"s@^(selinux=).*\$@\1enforcing@g"

$file

sed-rn

"/^(selinux=).*\$/p"

$file

echo

"請重啟伺服器才可以生效"

elif[[

$id==2

]];then

sed-ri

"s@^(selinux=).*\$@\1permissive@g"

$file

sed-rn

"/^(selinux=).*\$/p"

$file

echo

"請重啟伺服器才可以生效"

elif[[

$id==3

]];then

sed-ri

"s@^(selinux=).*\$@\1disabled@g"

$file

sed-rn

"/^(selinux=).*\$/p"

$file

echo

"請重啟伺服器才可以生效"

else

exit

fi

2、統計/etc/fstab檔案中每個檔案系統型別出現的次數

第一種

awk

'/^[^#|^$]/'

/etc/fstab

|uniq-c|

sort

-n

第二種

awk

'/^[^#]/end}'

/etc/fstab|sort

-nrk2

3,解決dos攻擊生產案例:根據web日誌或者或者網路連線數,監控當某個ip 併發連線數或者短時內pv達到100,即呼叫防火牆命令封掉對應的ip,監控頻 率每隔5分鐘。防火牆命令為:iptables -a input -s ip -j reject

#!/bin/bash

#author:

wuhen

while

true

donetstat

-an|

grep

estab

|awk

-f"[ :]+"''|

sort

|uniq-c|

while

read

line

dopv=`

echo

$line

|awk''`

ip=`echo

$line

|awk''`

if[$pv-gt

100]&&

[`iptables

-l-n

|grep

$ip|

wc-l

`-eq0]

;then

iptables

-ainput

-s$ip

-jreject

echo

"$ip is rejected"

>

/tmp

/reject_iptables_ip$

(date+%

f).log

fidone

sleep

180done

shell小指令碼

前言 可能這些指令碼看起來很簡單,很多人都不屑於去寫,但是一切複雜的東西都是由乙個個簡單的東西組合起來的。shell的語法比較怪異,和一般的程式語言有很大的區別,真的要多動手去寫才能學會的 1.要求 1.設定變數file的值為 etc passwd 2.依次向 etc passwd中的每個使用者問好...

Linux 常用shell小指令碼

1.計算指令碼運算時間 bin bash st date y m d h m s 運算過程開始 sleep 2 運算過程結束 en date y m d h m s st c date d st s en c date d en s interval expr en c st c echo star...

shell小指令碼 網速監控

在windows中,我們可以在360等管家軟體中顯示網速,在linux下想要檢視實時的網速怎麼辦呢?當然在linux下也有很多 思路 在執行ifconfig檢視網絡卡資訊的時候,可以看到以下內容 ifconfig wlp2s0 wlp2s0 flags 4163 mtu 1500 inet 192....