日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

shell脚本练习集合1

發布時間:2023/12/8 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 shell脚本练习集合1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

練習題

  • 練習題一:ifconfig 網卡可以顯示此網卡的信息
  • 練習題二:找出能登錄系統用戶中UID最大的用戶,并顯示其名稱
  • 練習題三:檢測系統中是否存在hellow用戶
  • 練習題四:檢測數字是否大于等于10,是輸出yes,不是輸出no
  • 練習題五:檢測目標是否存在,并判斷目標的類型
  • 練習題六:請顯示系統中能被su命令切換的用戶名稱
  • 練習題七:編寫腳本Apache.sh,此腳本接入的什么數字,http的端口就改為這個數字。(假設selinux關閉)

練習題一:ifconfig 網卡可以顯示此網卡的信息

顯示信息包含此網卡使用的ip地址,請用命令過濾此網卡ip,且只顯示ip不顯示其他信息

ifconfig | cut -d: '' 10 | head -2

練習題二:找出能登錄系統用戶中UID最大的用戶,并顯示其名稱

grep /bin/bash /etc/passwd | sort -t : -nrk 3 | head -1| cut -d: -f 1

練習題三:檢測系統中是否存在hellow用戶

方法一:
vim test.sh;

#!/bin/bash grep hellow /etc.passwd && { echo hellow is exits } || { echo hellow is not exits }

方法二:
vim test2.sh

#!/bin/bash read -p "please input a username:" username if id -u $username > /dev/null 2>&1; thenecho "user exists" elseecho "user not exists" fi

練習題四:檢測數字是否大于等于10,是輸出yes,不是輸出no

vim num_check.sh:

#!/bin/bash [ "$1" -ge "0" -a "$1" -lt "10" ] && { echo no } || { ech

o yes
}

練習題五:檢測目標是否存在,并判斷目標的類型

vim check.sh;

#!/bin/bash [ -z "$1" ] && { echo "Error:nothing fing, Please input something !!" exit }[ -e "$1" ] && { echo "Error: $1 is not exits !!" exit }[ -L "$1" ] && { echo "$1 is a link file" exit }[ -f "$1" ] && {echo " $1 is a common file"exit}[ -d "$1" ] && {echo "$1 is a directory"exit }[ -S "$1" ] && {echo "$1 is a socket"exit}[ -b "$1" ] && {echo "$1 is a device file"exit }[ -c "$1" ] && {echo "$1 is a char"exit }

練習題六:請顯示系統中能被su命令切換的用戶名稱

vim su.sh:

#!/bin/bash grep -E “bash$|sh$” /etc/passwd | cut -d : -f 1

練習題七:編寫腳本Apache.sh,此腳本接入的什么數字,http的端口就改為這個數字。(假設selinux關閉)

#!/bin/bash setenforce 0 &> /dev/null[ -z "$1" ] && {echo "Error:Please input port following script !!"exit }rpm -q httpd &> /dev/null || {echo "Error:Apache is not installed !!"exit }systemctl status httpd | grep "running" &> /dev/null || {echo "Error:Apache is not running !!"exit }netstat -antlupe | grep -E ":$1\>" &> /dev/null && {echo "Error:$1 is in used !!"exit }sed "/^Listen/cListen $1" -i /etc/httpd/conf/httpd.conf systemctl restart httpd

總結

以上是生活随笔為你收集整理的shell脚本练习集合1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。