需求:判断192.168.1.0/24网络中,当前在线的ip有哪些,并编写脚本打印出来。
root@openEuler \~\]# cat 1.sh #!/bin/bash for ip in $(seq 1 254); do ping -c 1 -W 1 "192.168.1.$ip" \> /dev/null 2\>\&1 if \[ $? -eq 0 \]; then echo "192.168.1.$ip is online" fi done 设计一个 [Shell](https://so.csdn.net/so/search?q=Shell&spm=1001.2101.3001.7020 "Shell") 程序,在/userdata 目录下建立50个目录,即 user1\~user50,并设置每个目录的权限,其中其他用户的权限为:读;文件所有者的权限为:读、写、执行;文件所有者所在组的权限为:读、执行。 \[root@openEuler \~\]# cat 2.sh #!/bin/bash mkdir -p /userdata for i in {1..50}; do dir="/userdata/user$i" mkdir -p "$dir" chmod 754 "$dir" echo "Created and set permissions for $dir" done 结果 \[root@openEuler \~\]# sh 2.sh \[root@openEuler \~\]# ll /userdata total 200 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_1 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_10 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_11 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_12 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_13 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_14 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_15 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_16 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_17 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_18 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_19 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_2 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_20 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_21 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_22 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_23 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_24 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_25 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_26 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_27 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_28 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_29 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_3 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_30 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_31 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_32 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_33 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_34 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_35 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_36 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_37 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_38 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_39 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_4 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_40 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_41 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_42 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_43 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_44 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_45 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_46 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_47 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_48 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_49 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_5 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_50 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_6 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_7 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_8 drwxr-xr-- 2 root root 4096 Jan 14 08:47 user_9