zl程序教程

您现在的位置是:首页 >  其他

当前栏目

S20.shell脚本每日一练

shell 脚本 每日
2023-09-14 09:15:22 时间

39.查看/sbin/nologin的shell类型的用户名和UID

[root@rocky8 ~]# vim while_read_passwd.sh
#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2021-10-20
#FileName:      while_read_passwd.sh
#URL:           raymond.blog.csdn.net
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************

while read line ;do
    if [[ "$line" =~ /sbin/nologin$ ]] ;then
        echo $line | cut -d: -f1,3
    fi
done < /etc/passwd

[root@rocky8 ~]# bash while_read_passwd.sh 
bin:1
daemon:2
adm:3
lp:4
mail:8
operator:11
games:12
ftp:14
nobody:65534
dbus:81
systemd-coredump:999
systemd-resolve:193
tss:59
polkitd:998
unbound:997
sssd:996
sshd:74

40.实现进度条功能

[root@rocky8 ~]# vim progress_chart.sh
#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2021-10-21
#FileName:      progress_chart.sh
#URL:           raymond.blog.csdn.net
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
function print_chars(){
    # 传入的第一个参数指定要打印的字符串
    local char="$1"
    # 传入的第二个参数指定要打印多少次指定的字符串
    local number="$2"
    local c
    for ((c = 0; c < number; ++c)); do
        printf "$char"
    done
}

COLOR=32
declare -i end=50
for ((i = 1; i <= end; ++i)); do
    printf "\e[1;${COLOR}m\e[80D["
    print_chars "#" $i
    print_chars " " $((end - i))
    printf "] %3d%%\e[0m" $((i * 2))
    sleep 0.1s
done
echo

[root@rocky8 ~]# bash progress_chart.sh 
[##################################################] 100%