firewalld的富规则:
NAT:
- firewall-cmd --permanent --add-masquerade
- firewall-cmd --reload
复制代码
DNAT:
- firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.0.0/24 forward-port port=80 protocol=tcp to-port=80 to-addr=172.31.128.3'
复制代码
SELinux:
- semanage fcontext -l
- semanage boolean -l
- semanage port -l
复制代码
httpd.conf的端口改为82,
报以下的错误就是SELinux端口阻挡:
- [root@server3 conf]# systemctl restart httpd
- Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
复制代码- semanage port -a -t http_port_t -p tcp 82
复制代码
----------------------------------------------------------
shell编程:
- for i in * ; do du -s $i 2> /dev/null ; done |sort -n
复制代码 ------好习惯的例子-----
2.lib:
- sub_du() {
- read -p "PLS input the directory: " v_dir
- (for i in ${v_dir}*
- do
- du -s $i 2>/dev/null
- done) | sort -n
- }
复制代码
2.sh
- #!/bin/sh
- source /root/labs/2.lib
- sub_du
复制代码
-------------------------------------------
注意位置参数:
- [root@server3 labs]# cat 3.sh
- echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $10
- [root@server3 labs]# ./3.sh 1 2 3 4 5 6 7 8 9 a
- 1 2 3 4 5 6 7 8 9 10
- [root@server3 labs]# vim 3.sh
- [root@server3 labs]# cat 3.sh
- echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10}
- [root@server3 labs]# ./3.sh 1 2 3 4 5 6 7 8 9 a
- 1 2 3 4 5 6 7 8 9 a
复制代码 -------------------------关于整型数运算:
- v_random=$[ $RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM % 30 + 1 ]
- #echo $v_random
- if [ $v_random -lt 0 ]
- then
- if [ $v_random -eq -30 ]
- then
- echo $[ 31 + $v_random ]
- else
- echo $[ 30 + $v_random ]
- fi
- else
- echo $v_random
- fi
复制代码
--------关于浮点数
-
- #!/bin/sh
- read -p "Num1: " v_num1
- read -p "Num2: " v_num2
- bc <<EOF
- scale=4
- $v_num1 / $v_num2
- EOF
复制代码
-------不定循环次数
- #!/bin/sh
- while [ ! -f /root/labs/6.txt ]
- do
- sleep 1
- done
- cat /root/labs/6.txt
复制代码 -------------------------RH254 P357
- #!/bin/sh
- sub_float() {
- bc <<EOF
- scale=3
- ( $1 / $2 ) * 100
- EOF
- }
- v_fmt="--skip-column-names -E"
- v_cmd='show databases'
- v_backupdir="/dbbackup"
- for i in $(mysql $v_fmt -u root -e "$v_cmd" | grep -v '^*' | grep -v information_schema | grep -v performance_schema)
- do
- echo "Backing up $i"
- mysqldump -u root $i >$v_backupdir/${i}.dump
- done
- v_total=0
- for i in $v_backupdir/*
- do
- v_size=$(stat --printf "%s\n" $i)
- v_total=$[ $v_total + $v_size ]
- done
- for i in $v_backupdir/*
- do
- v_size=$(stat --printf "%s\n" $i)
- echo "$i, $v_size, $(sub_float $v_size $v_total)%"
- done
复制代码 [root@server3 labs]# ./7.sh
Backing up mysql
Backing up test
/dbbackup/mysql.dump, 514664, 99.700%
/dbbackup/test.dump, 1261, .200%
--------------------------------------------------------
以下是判断网络情况程序:
- #!/bin/sh
- rm -f /tmp/8.txt
- for i in {1..254}
- do
- (if ping -c 2 -W 1 -q 192.168.0.$i > /dev/null 2>&1
- then
- echo 192.168.0.$i is online
- fi) >> /tmp/8.txt &
- done
- wait
- cat /tmp/8.txt
复制代码
改写成:
- sub_ping() {
- rm -f /tmp/sub_ping.txt
- for i in {1..254}
- do
- (if ping -c 8 -W 1 -q $SUBCON1.$i > /dev/null 2>&1
- then
- echo 192.168.0.$i is online
- fi )>> /tmp/sub_ping.txt &
- done
- wait
- sort -t . -k 4 -n /tmp/sub_ping.txt
- }
复制代码
- [root@server3 labs]# vim 8.lib
- [root@server3 labs]# cat 8.sh
- #!/bin/sh
- . /root/labs/8.lib
- sub_ping
复制代码
---------------------子程序的其他例子:
- sub_answer() {
- unset SUBANS
-
- sub_sub_answer(){
- SUBANS=`echo $SUBANS |tr -d "[:blank:]"`
- if [ -z $SUBANS ]
- then
- SUBANS="NULL"
- fi
- }
-
- read -p "$1" SUBANS
- sub_sub_answer
-
- until [ $SUBANS == "y" -o $SUBANS == "n" ]
- do
- echo "This question should be answered either with "y" or "n"."
- read -p "$1" SUBANS
- sub_sub_answer
- done
-
- }
复制代码- #!/bin/sh
- . /usr/lib/botang-func
- sub_answer "Pls input: "
- [ $SUBANS == "y" ] && echo "OK"
复制代码 ----------------------------------
- sub_confirm() {
- unset SUBCON1
- unset SUBCON2
- SUBCON1=0
- SUBCON2=1
- until [ $SUBCON1 == $SUBCON2 ]
- do
- read -p "$1" SUBCON1
- sub_answer "Input is: "$SUBCON1". Are you sure ?(y/n)"
- if [ -z $SUBCON1 ]
- then
- SUBCON1="NULL"
- fi
- if [ $SUBANS == "y" ]
- then
- SUBCON2=$SUBCON1
- fi
- done
- }
-
复制代码- #!/bin/sh
- . ./10.lib
- sub_confirm "Pls input :"
- echo "Your input is $SUBCON1"
复制代码
显示红色:
- sub_red() {
- echo -e "\033[31;1m${1}\033[0m"
- }
复制代码
显示绿色:
- sub_green() {
- echo -e "\033[32;1m${1}\033[0m"
- }
复制代码 显示红色闪烁:
- sub_red_blink() {
- echo -e "\033[31;5;1m${1}\033[0m"
- }
复制代码 显示绿色闪烁:
- sub_green_blink() {
- echo -e "\033[32;5;1m${1}\033[0m"
- }
复制代码
|