Bo's Oracle Station

查看: 1847|回复: 0

课程第31/32次

[复制链接]
匿名
匿名  发表于 2019-9-22 20:47:07 |阅读模式

firewalld的富规则:

NAT:
  1. firewall-cmd --permanent --add-masquerade
  2. firewall-cmd --reload
复制代码

DNAT:
  1. 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'
复制代码
  1. firewall-cmd   --reload
复制代码

SELinux:
  1. semanage fcontext -l
  2. semanage boolean -l
  3. semanage port -l
复制代码

httpd.conf的端口改为82,
报以下的错误就是SELinux端口阻挡:
  1. [root@server3 conf]# systemctl restart httpd
  2. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
复制代码
  1. semanage port -a -t http_port_t  -p tcp 82
复制代码

----------------------------------------------------------
shell编程:
  1. for i in * ; do du -s $i 2> /dev/null  ; done  |sort -n
复制代码
------好习惯的例子-----

2.lib:

  1. sub_du() {
  2. read -p "PLS input the directory: " v_dir
  3. (for i in ${v_dir}*
  4. do
  5.   du -s $i 2>/dev/null
  6. done) | sort -n
  7. }
复制代码

2.sh
  1. #!/bin/sh

  2. source  /root/labs/2.lib

  3. sub_du
复制代码

-------------------------------------------
注意位置参数:
  1. [root@server3 labs]# cat 3.sh  
  2. echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $10
  3. [root@server3 labs]# ./3.sh 1 2 3 4 5 6 7 8 9 a
  4. 1 2 3 4 5 6 7 8 9 10
  5. [root@server3 labs]# vim 3.sh
  6. [root@server3 labs]# cat 3.sh                  
  7. echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10}
  8. [root@server3 labs]# ./3.sh 1 2 3 4 5 6 7 8 9 a  
  9. 1 2 3 4 5 6 7 8 9 a
复制代码
-------------------------关于整型数运算:
  1. v_random=$[ $RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM  % 30 + 1 ]

  2. #echo $v_random

  3. if [ $v_random -lt 0 ]
  4. then
  5. if [ $v_random -eq -30 ]
  6. then
  7.   echo $[ 31 + $v_random ]
  8. else
  9.   echo $[ 30 + $v_random ]
  10. fi
  11. else
  12. echo $v_random
  13. fi
复制代码

--------关于浮点数
  1.   

  2. #!/bin/sh

  3. read -p "Num1: " v_num1
  4. read -p "Num2: " v_num2
  5. bc <<EOF
  6. scale=4
  7. $v_num1 / $v_num2
  8. EOF
复制代码

-------不定循环次数
  1. #!/bin/sh

  2. while [ ! -f /root/labs/6.txt ]
  3. do
  4. sleep 1
  5. done

  6. cat /root/labs/6.txt
复制代码
-------------------------RH254  P357

  1. #!/bin/sh

  2. sub_float() {
  3. bc <<EOF
  4. scale=3
  5. ( $1 / $2 ) * 100
  6. EOF
  7. }


  8. v_fmt="--skip-column-names -E"
  9. v_cmd='show databases'
  10. v_backupdir="/dbbackup"
  11. for i in $(mysql $v_fmt -u root -e "$v_cmd" | grep -v '^*' | grep -v information_schema | grep -v performance_schema)
  12. do
  13. echo "Backing up $i"
  14. mysqldump -u root $i >$v_backupdir/${i}.dump
  15. done
  16. v_total=0

  17. for i in $v_backupdir/*
  18. do
  19. v_size=$(stat --printf "%s\n" $i)
  20. v_total=$[ $v_total + $v_size ]
  21. done

  22. for i in  $v_backupdir/*
  23. do
  24.   v_size=$(stat --printf "%s\n" $i)
  25. echo "$i, $v_size,  $(sub_float $v_size  $v_total)%"
  26. done
复制代码
[root@server3 labs]# ./7.sh
Backing up mysql
Backing up test
/dbbackup/mysql.dump, 514664,  99.700%
/dbbackup/test.dump, 1261,  .200%
--------------------------------------------------------
以下是判断网络情况程序:
  1. #!/bin/sh

  2. rm -f /tmp/8.txt
  3. for i in {1..254}
  4. do
  5. (if  ping -c 2 -W 1 -q 192.168.0.$i > /dev/null 2>&1
  6. then
  7.   echo 192.168.0.$i is online
  8. fi) >> /tmp/8.txt   &
  9. done

  10. wait

  11. cat /tmp/8.txt
复制代码

改写成:

  1. sub_ping() {
  2. rm -f /tmp/sub_ping.txt
  3. for i in {1..254}
  4. do
  5.   (if  ping -c 8 -W 1 -q $SUBCON1.$i > /dev/null 2>&1
  6.   then
  7.    echo 192.168.0.$i is online
  8.   fi )>> /tmp/sub_ping.txt &
  9. done  
  10. wait
  11. sort -t . -k 4 -n /tmp/sub_ping.txt
  12. }
复制代码


  1. [root@server3 labs]# vim 8.lib
  2. [root@server3 labs]# cat 8.sh
  3. #!/bin/sh
  4. .   /root/labs/8.lib

  5. sub_ping
复制代码

---------------------子程序的其他例子:

  1. sub_answer() {
  2.         unset SUBANS
  3.         
  4.         sub_sub_answer(){
  5.                 SUBANS=`echo $SUBANS |tr -d "[:blank:]"`
  6.                 if [ -z $SUBANS ]
  7.                 then
  8.                 SUBANS="NULL"
  9.                 fi
  10.         }
  11.         
  12.         read -p "$1" SUBANS
  13.         sub_sub_answer
  14.         
  15.         until [ $SUBANS ==  "y"  -o  $SUBANS ==  "n" ]
  16.         do
  17.                 echo "This question should be answered either with "y" or "n"."
  18.                 read -p "$1" SUBANS
  19.                 sub_sub_answer
  20.         done
  21.         
  22. }
复制代码
  1. #!/bin/sh

  2. .   /usr/lib/botang-func

  3. sub_answer "Pls input: "

  4. [ $SUBANS == "y" ] && echo "OK"
复制代码
----------------------------------
  1. sub_confirm() {
  2.         unset SUBCON1
  3.         unset SUBCON2
  4.         SUBCON1=0
  5.         SUBCON2=1
  6.         until [ $SUBCON1 == $SUBCON2 ]
  7.         do
  8.                 read -p "$1" SUBCON1
  9.                 sub_answer "Input is: "$SUBCON1". Are you sure ?(y/n)"
  10.                 if [ -z $SUBCON1 ]
  11.                 then
  12.                  SUBCON1="NULL"
  13.                 fi
  14.                 if [ $SUBANS == "y" ]
  15.                 then
  16.                 SUBCON2=$SUBCON1
  17.                 fi
  18.         done
  19. }

  20.         
复制代码
  1. #!/bin/sh


  2. .  ./10.lib

  3. sub_confirm "Pls input :"

  4. echo "Your input is  $SUBCON1"

复制代码

显示红色:
  1. sub_red() {
  2. echo -e "\033[31;1m${1}\033[0m"
  3. }
复制代码

显示绿色:
  1. sub_green() {
  2.   echo -e "\033[32;1m${1}\033[0m"
  3. }
复制代码
显示红色闪烁:
  1. sub_red_blink() {
  2. echo -e "\033[31;5;1m${1}\033[0m"
  3. }
复制代码
显示绿色闪烁:
  1. sub_green_blink() {
  2.   echo -e "\033[32;5;1m${1}\033[0m"
  3. }
复制代码






























回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-11-21 19:56 , Processed in 0.038884 second(s), 24 queries .

快速回复 返回顶部 返回列表