当前位置: 首页 > news >正文

Linux92 shell:倒计时,用户分类

问题

while IFS= read -r line;do

在这里插入图片描述

oot@web kk]# tail -6 /etc/passwd
user1r4:x:1040:1040::/home/user1r4:/bin/bash
useros20:x:1041:1041::/home/useros20:/bin/bash
useros21:x:1042:1042::/home/useros21:/bin/bash
useros22:x:1043:1043::/home/useros22:/bin/bash
useros23:x:1044:1044::/home/useros23:/bin/bash
useros24:x:1045:1045::/home/useros24:/bin/bash
[root@web kk]# grep 0 /etc/pa
pam.d/     papersize  passwd     passwd-
[root@web kk]# grep '0' /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
sssd:x:990:984:User for sssd:/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
caozx26:x:1000:1002:caozx26:/home/caozx26:/bin/bash
XOAP:x:1002:1000::/rhome/XOAP:/bin/bash
mysql:x:1003:1003::/home/mysql:/sbin/nologin
cao1:x:1004:1223::/home/cao1:/bin/bash
cao2:x:1005:1005::/home/cao2:/bin/bash
xiaocao:x:1006:1006::/home/xiaocao:/bin/bash
xiao6:x:1007:1007::/home/xiao6:/bin/bash
tom:x:1008:1008::/home/tom:/bin/bash
jack:x:1009:1009::/home/jack:/bin/bash
cw01:x:1010:1224::/home/cw01:/bin/bash
sc01:x:1011:1226::/home/sc01:/bin/bash
rs01:x:1012:1225::/home/rs01:/bin/bash
boss01:x:1013:1004::/home/boss01:/bin/bash
cw02:x:1014:1224::/home/cw02:/bin/bash
sc02:x:1015:1226::/home/sc02:/bin/bash
rs02:x:1016:1225::/home/rs02:/bin/bash
harry:x:1017:1017::/home/mahei/redhat/harry:/bin/bash
netasha:x:1018:1018::/home/netasha:/bin/bash
sarsh:x:1019:1228::/home/sarsh:/bin/bash
OOO:x:1020:1020::/home/OOO:/bin/bash
jerry:x:1021:1229::/home/jerry:/bin/bash
kefu:x:1022:1022::/home/kefu:/bin/bash
kefu2:x:1023:1023::/home/kefu2:/bin/bash
user01:x:1024:1024::/home/user01:/bin/bash
u4:x:1025:1025::/home/u4:/bin/bash
u1:x:1026:1026::/home/u1:/bin/bash
u2:x:1027:1027::/home/u2:/bin/bash
u3:x:1028:1028::/home/u3:/bin/bash
u5:x:1029:1029::/home/u5:/bin/bash
stu0:x:1030:1030::/rhome:/bin/bash
stu1:x:1031:1031::/rhome:/bin/bash
stu2:x:1032:1032::/rhome:/bin/bash
stu3:x:1033:1033::/rhome:/bin/bash
stu4:x:1034:1034::/rhome:/bin/bash
stu5:x:1035:1035::/rhome:/bin/bash
user1r0:x:1036:1036::/home/user1r0:/bin/bash
user1r1:x:1037:1037::/home/user1r1:/bin/bash
user1r2:x:1038:1038::/home/user1r2:/bin/bash
user1r3:x:1039:1039::/home/user1r3:/bin/bash
user1r4:x:1040:1040::/home/user1r4:/bin/bash
useros20:x:1041:1041::/home/useros20:/bin/bash
useros21:x:1042:1042::/home/useros21:/bin/bash
useros22:x:1043:1043::/home/useros22:/bin/bash
useros23:x:1044:1044::/home/useros23:/bin/bash
useros24:x:1045:1045::/home/useros24:/bin/bash
您在 /var/spool/mail/root 中有邮件
[root@web kk]# a=$( grep '0' /etc/passwd )
您在 /var/spool/mail/root 中有邮件
[root@web kk]# echo $a
root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin qemu:x:107:107:qemu user:/:/sbin/nologin sssd:x:990:984:User for sssd:/:/sbin/nologin avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin caozx26:x:1000:1002:caozx26:/home/caozx26:/bin/bash XOAP:x:1002:1000::/rhome/XOAP:/bin/bash mysql:x:1003:1003::/home/mysql:/sbin/nologin cao1:x:1004:1223::/home/cao1:/bin/bash cao2:x:1005:1005::/home/cao2:/bin/bash xiaocao:x:1006:1006::/home/xiaocao:/bin/bash xiao6:x:1007:1007::/home/xiao6:/bin/bash tom:x:1008:1008::/home/tom:/bin/bash jack:x:1009:1009::/home/jack:/bin/bash cw01:x:1010:1224::/home/cw01:/bin/bash sc01:x:1011:1226::/home/sc01:/bin/bash rs01:x:1012:1225::/home/rs01:/bin/bash boss01:x:1013:1004::/home/boss01:/bin/bash cw02:x:1014:1224::/home/cw02:/bin/bash sc02:x:1015:1226::/home/sc02:/bin/bash rs02:x:1016:1225::/home/rs02:/bin/bash harry:x:1017:1017::/home/mahei/redhat/harry:/bin/bash netasha:x:1018:1018::/home/netasha:/bin/bash sarsh:x:1019:1228::/home/sarsh:/bin/bash OOO:x:1020:1020::/home/OOO:/bin/bash jerry:x:1021:1229::/home/jerry:/bin/bash kefu:x:1022:1022::/home/kefu:/bin/bash kefu2:x:1023:1023::/home/kefu2:/bin/bash user01:x:1024:1024::/home/user01:/bin/bash u4:x:1025:1025::/home/u4:/bin/bash u1:x:1026:1026::/home/u1:/bin/bash u2:x:1027:1027::/home/u2:/bin/bash u3:x:1028:1028::/home/u3:/bin/bash u5:x:1029:1029::/home/u5:/bin/bash stu0:x:1030:1030::/rhome:/bin/bash stu1:x:1031:1031::/rhome:/bin/bash stu2:x:1032:1032::/rhome:/bin/bash stu3:x:1033:1033::/rhome:/bin/bash stu4:x:1034:1034::/rhome:/bin/bash stu5:x:1035:1035::/rhome:/bin/bash user1r0:x:1036:1036::/home/user1r0:/bin/bash user1r1:x:1037:1037::/home/user1r1:/bin/bash user1r2:x:1038:1038::/home/user1r2:/bin/bash user1r3:x:1039:1039::/home/user1r3:/bin/bash user1r4:x:1040:1040::/home/user1r4:/bin/bash useros20:x:1041:1041::/home/useros20:/bin/bash useros21:x:1042:1042::/home/useros21:/bin/bash useros22:x:1043:1043::/home/useros22:/bin/bash useros23:x:1044:1044::/home/useros23:/bin/bash useros24:x:1045:1045::/home/useros24:/bin/bash
[root@web kk]# grep :0: /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
operator:x:11:0:operator:/root:/sbin/nologin
您在 /var/spool/mail/root 中有邮件
[root@web kk]# b=$( grep ':0:' /etc/passwd )
您在 /var/spool/mail/root 中有邮件
[root@web kk]# echo $b
root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt operator:x:11:0:operator:/root:/sbin/nologin
[root@web kk]# c=$( echo $b|cut -d ":" -f3 )
您在 /var/spool/mail/root 中有邮件
[root@web kk]# echo $c
0
[root@web kk]# cd ~
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ls
1828.txt                head2.txt                  ok                 tail7
1837.txt                head4                      okl                tail.txt
1.txt                   head5                      pas3.txt           ta.txt
2-1.java                head6                      pas4.txt           test1.sh
2.java                  head7                      pas5.txt           testcfor.sh
=6                      he.txt                     pas6.txt           testff1.sh
alll1                   httpd-2.4.37               pas7.txt           testff.sh
anaconda-ks.cfg         httpd-2.4.37.tar.bz2       passwd1.txt        testfor2.sh
app                     id.sh                      paste1.txt         testfor3.sh
apr-1.5.2               initial-setup-ks.cfg       pa.txt             testfor4.sh
apr-1.5.2.tar.bz2       inotify-tools-3.13.tar.gz  ph1.txt            testforf.sh
apr-util-1.5.4          ip.txt                     phonenum.txt       testfor.sh
apr-util-1.5.4.tar.bz2  judgefn.sh                 phon.txt           uc.sh
axel-2.4                judgepath.sh               pho.sh             uname2.sh
axel-2.4.tar.gz         judgeprimeok.sh            php-7.2.17         unameok.sh
bb.conf                 judgeprime.sh              php-7.2.17.tar.xz  uname.sh
cc.conf                 kk                         ping2.sh           up1.sh
classfi.sh              lc3.txt                    ping.sh            up2.sh
code                    lc4.txt                    primeok.sh         url.sh
cuser1.sh               lc5.txt                    process1.sh        ur.sh
dir1                    lc6.txt                    process.sh         user1c.sh
dn.sh                   lc7.txt                    psok.sh            useradd1.sh
expect1.sh              lc.sh                      pub                useradd.sh
expect4.sh              lc.txt                     readme7            userad.sh
expect5c.sh             lk.txt                     readme.txt         user.sh
expect5.sh              logs                       rsa.sh             vsftpd1.sh
expect6.sh              luad.txt                   serverOk.sh        vsftpd2.sh
expect.sh               luck.sh                    service-s.sh       vsftpdins.sh
fi1.txt                 lucky1.txt                 shift.sh           vsftpdok.sh
file20.java             lucky.txt                  Steam.dll          vsftpd.sh
file23.java             luvk.txt                   stuc.sh            vstest.sh
for51.sh                mysql-5.6.31               sum.sh             wordpress
for5.sh                 mysql-5.6.31.tar.gz        tail               wordpress-4.7.3-zh_CN.tar.gz
ftpok.sh                no.txt                     tail4              yearok.sh
ftp.sh                  null                       tail5
head                    num.sh                     tail6
[root@web ~]# cat /etc/passwd >>u1.txt
您在 /var/spool/mail/root 中有邮件
[root@web ~]# tail -6 u1.txt
user1r4:x:1040:1040::/home/user1r4:/bin/bash
useros20:x:1041:1041::/home/useros20:/bin/bash
useros21:x:1042:1042::/home/useros21:/bin/bash
useros22:x:1043:1043::/home/useros22:/bin/bash
useros23:x:1044:1044::/home/useros23:/bin/bash
useros24:x:1045:1045::/home/useros24:/bin/bash
[root@web ~]#
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS=read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done
[root@web ~]# ./user1.sh
./user1.sh:行2: -r: 未找到命令

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./user1.sh
^C您在 /var/spool/mail/root 中有邮件

在这里插入图片描述

[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done < user2.txt
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./user1.sh
grep: root:x:0:0:root:/root:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: bin:x:1:1:bin:/bin:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: daemon:x:2:2:daemon:/sbin:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: adm:x:3:4:adm:/var/adm:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: sync:x:5:0:sync:/sbin:/bin/sync: 没有那个文件或

在这里插入图片描述
在这里插入图片描述
倒计时
date +%s

[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [ $tar =~ ^[0-9]{0-4}-[0-9]{0-2}-{0-9}[0-2] ];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# chmod +x upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2024-12-22
./upt.sh: 第 2 行:[: =~: 期待二元表达式
wrong
[root@web ~]#
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [ $tar =~ ^[0-9]{0-4}-[0-9]{0-2}-{0-9}[0-2]$ ];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# ./upt.sh
pl input a date:2024-2-12
./upt.sh: 第 2 行:[: =~: 期待二元表达式
wrong
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:1202-12-12
./upt.sh: 第 2 行:[: =~: 期待二元表达式
wrong
[root@web ~]#
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{0-4}-[0-9]{0-2}-{0-9}[0-2]$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# ./u
uc.sh        uname.sh     upt.sh       user1c.sh    useradd.sh
uname2.sh    up1.sh       url.sh       user1.sh     userad.sh
unameok.sh   up2.sh       ur.sh        useradd1.sh  user.sh
[root@web ~]# ./upt.sh
pl input a date:2011-02-12
wrong
[root@web ~]#
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-{0-9}[2]$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2023-02-12
wrong
[root@web ~]#

在这里插入图片描述
在这里插入图片描述

[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se / 86400 ))
ago_hours=$(( (agoday % 86400) /3600))
ago_minutes=$(((agoday %3600)/60))
ago_se=$(( agoday % 60 ))
if [ "$cut_se" -gt 0 ];then
echo ""$tar" is "$agoday"day "$ago_hours"h "$ago_minutes"min "$ago_se"s ago"
else
day=$(( agoday * -1 ))
hours=$(( ago_hours * -1 ))
minutes=$(( ago_minutes * -1 ))
se=$(( ago * -1 ))
echo ""$tar" is "$day"day "$hours"h "$minutes"m "$se"s after"fi
[root@web ~]# ./upt.sh
pl input a date:2012-12-21
2012-12-21 is 4638day 1h 17min 18s ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2033-12-22
2033-12-22 is 3032day 0h 50m 0s after
[root@web ~]# ./upt.sh
pl input a date:2092-12-10
2092-12-10 is 24570day 6h 49m 0s after
[root@web ~]#

212-12=200
12-212=-200
123-11=112
11-123=-112

shell

倒计时

[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se / 86400 ))
ago_hours=$((( cut_se % 86400) /3600))
ago_minutes=$(((cut_se %3600)/60))
ago_se=$(( cut_se % 60 ))
if [ "$cut_se" -gt 0 ];then
echo ""$tar" is "$agoday"day "$ago_hours"h "$ago_minutes"min "$ago_se"s ago"
else
day=$(( agoday * -1 ))
hours=$(( ago_hours * -1 ))
minutes=$(( ago_minutes * -1 ))
se=$(( ago_se * -1 ))
echo ""$tar" is "$day"day "$hours"h "$minutes"m "$se"s after"fi
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2019-12-12
2019-12-12 is 2091day 23h 4min 48s ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2028-12-21
2028-12-21 is 1205day 0h 53m 28s after
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2035-12-21
2035-12-21 is 3761day 0h 50m 5s after
您在 /var/spool/mail/root 中有邮件
[root@web ~]#

用户分类

[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
b=$( echo "$line"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line" >>root1.txt
elif [ "$b" -gt 0 ] && [ "$b" -lt 1000 ];then
echo "$line" >> system12.txt
elif [ "$b" -ge 1000 ];then
echo "$line" >> normal12.txt
fi
done < user2.txt
[root@web ~]# cat system12.txt
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
libstoragemgmt:x:998:995:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
colord:x:997:994:User for colord:/var/lib/colord:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
saned:x:996:993:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
gluster:x:995:992:GlusterFS daemons:/run/gluster:/sbin/nologin
saslauth:x:994:76:Saslauthd user:/run/saslauthd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
chrony:x:992:987::/var/lib/chrony:/sbin/nologin
unbound:x:991:986:Unbound DNS resolver:/etc/unbound:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
sssd:x:990:984:User for sssd:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
geoclue:x:989:983:User for geoclue:/var/lib/geoclue:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@web ~]# cat normal12.txt
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
caozx26:x:1000:1002:caozx26:/home/caozx26:/bin/bash
XOAP:x:1002:1000::/rhome/XOAP:/bin/bash
mysql:x:1003:1003::/home/mysql:/sbin/nologin
cao1:x:1004:1223::/home/cao1:/bin/bash
cao2:x:1005:1005::/home/cao2:/bin/bash
xiaocao:x:1006:1006::/home/xiaocao:/bin/bash
xiao6:x:1007:1007::/home/xiao6:/bin/bash
tom:x:1008:1008::/home/tom:/bin/bash
jack:x:1009:1009::/home/jack:/bin/bash
cw01:x:1010:1224::/home/cw01:/bin/bash
sc01:x:1011:1226::/home/sc01:/bin/bash
rs01:x:1012:1225::/home/rs01:/bin/bash
boss01:x:1013:1004::/home/boss01:/bin/bash
cw02:x:1014:1224::/home/cw02:/bin/bash
sc02:x:1015:1226::/home/sc02:/bin/bash
rs02:x:1016:1225::/home/rs02:/bin/bash
harry:x:1017:1017::/home/mahei/redhat/harry:/bin/bash
netasha:x:1018:1018::/home/netasha:/bin/bash
sarsh:x:1019:1228::/home/sarsh:/bin/bash
OOO:x:1020:1020::/home/OOO:/bin/bash
jerry:x:1021:1229::/home/jerry:/bin/bash
kefu:x:1022:1022::/home/kefu:/bin/bash
kefu2:x:1023:1023::/home/kefu2:/bin/bash
user01:x:1024:1024::/home/user01:/bin/bash
u4:x:1025:1025::/home/u4:/bin/bash
u1:x:1026:1026::/home/u1:/bin/bash
u2:x:1027:1027::/home/u2:/bin/bash
u3:x:1028:1028::/home/u3:/bin/bash
u5:x:1029:1029::/home/u5:/bin/bash
stu0:x:1030:1030::/rhome:/bin/bash
stu1:x:1031:1031::/rhome:/bin/bash
stu2:x:1032:1032::/rhome:/bin/bash
stu3:x:1033:1033::/rhome:/bin/bash
stu4:x:1034:1034::/rhome:/bin/bash
stu5:x:1035:1035::/rhome:/bin/bash
user1r0:x:1036:1036::/home/user1r0:/bin/bash
user1r1:x:1037:1037::/home/user1r1:/bin/bash
user1r2:x:1038:1038::/home/user1r2:/bin/bash
user1r3:x:1039:1039::/home/user1r3:/bin/bash
user1r4:x:1040:1040::/home/user1r4:/bin/bash
useros20:x:1041:1041::/home/useros20:/bin/bash
useros21:x:1042:1042::/home/useros21:/bin/bash
useros22:x:1043:1043::/home/useros22:/bin/bash
useros23:x:1044:1044::/home/useros23:/bin/bash
useros24:x:1045:1045::/home/useros24:/bin/bash

记录

root@192.168.235.20's password:┌────────────────────────────────────────────────────────────────────┐│                        • MobaXterm 20.0 •                          ││            (SSH client, X-server and networking tools)             ││                                                                    ││ ➤ SSH session to root@192.168.235.20                               ││   • SSH compression : ✘                                            ││   • SSH-browser     : ✔                                            ││   • X11-forwarding  : ✔  (remote display is forwarded through SSH) ││   • DISPLAY         : ✔  (automatically set on remote server)      ││                                                                    ││ ➤ For more info, ctrl+click on help or visit our website           │└────────────────────────────────────────────────────────────────────┘Last login: Mon Sep  1 19:13:02 2025 from 192.168.235.1
[root@web ~]# ls
1828.txt                head2.txt                  ok                 tail7
1837.txt                head4                      okl                tail.txt
1.txt                   head5                      pas3.txt           ta.txt
2-1.java                head6                      pas4.txt           test1.sh
2.java                  head7                      pas5.txt           testcfor.sh
=6                      he.txt                     pas6.txt           testff1.sh
alll1                   httpd-2.4.37               pas7.txt           testff.sh
anaconda-ks.cfg         httpd-2.4.37.tar.bz2       passwd1.txt        testfor2.sh
app                     id.sh                      paste1.txt         testfor3.sh
apr-1.5.2               initial-setup-ks.cfg       pa.txt             testfor4.sh
apr-1.5.2.tar.bz2       inotify-tools-3.13.tar.gz  ph1.txt            testforf.sh
apr-util-1.5.4          ip.txt                     phonenum.txt       testfor.sh
apr-util-1.5.4.tar.bz2  judgefn.sh                 phon.txt           u1.txt
axel-2.4                judgepath.sh               pho.sh             uc.sh
axel-2.4.tar.gz         judgeprimeok.sh            php-7.2.17         uname2.sh
bb.conf                 judgeprime.sh              php-7.2.17.tar.xz  unameok.sh
cc.conf                 kk                         ping2.sh           uname.sh
classfi.sh              lc3.txt                    ping.sh            up1.sh
code                    lc4.txt                    primeok.sh         up2.sh
cuser1.sh               lc5.txt                    process1.sh        url.sh
dir1                    lc6.txt                    process.sh         ur.sh
dn.sh                   lc7.txt                    psok.sh            user1c.sh
expect1.sh              lc.sh                      pub                useradd1.sh
expect4.sh              lc.txt                     readme7            useradd.sh
expect5c.sh             lk.txt                     readme.txt         userad.sh
expect5.sh              logs                       rsa.sh             user.sh
expect6.sh              luad.txt                   serverOk.sh        vsftpd1.sh
expect.sh               luck.sh                    service-s.sh       vsftpd2.sh
fi1.txt                 lucky1.txt                 shift.sh           vsftpdins.sh
file20.java             lucky.txt                  Steam.dll          vsftpdok.sh
file23.java             luvk.txt                   stuc.sh            vsftpd.sh
for51.sh                mysql-5.6.31               sum.sh             vstest.sh
for5.sh                 mysql-5.6.31.tar.gz        tail               wordpress
ftpok.sh                no.txt                     tail4              wordpress-4.7.3-zh_CN.tar.gz
ftp.sh                  null                       tail5              yearok.sh
head                    num.sh                     tail6
[root@web ~]# cat usc.sh
cat: usc.sh: 没有那个文件或目录
[root@web ~]# cat usc.sh
cat: usc.sh: 没有那个文件或目录
您在 /var/spool/mail/root 中有新邮件
[root@web ~]# vim usc.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# while IFS= read -r lines;do
> ^C
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim usc.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat usc.sh
cat /etc/passwd > user1.txt
while IFS= read -r line;do[root@web ~]# grep ":0:" /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
operator:x:11:0:operator:/root:/sbin/nologin
您在 /var/spool/mail/root 中有邮件
[root@web ~]# a=$(grep ":0:" /etc/passwd)
您在 /var/spool/mail/root 中有邮件
[root@web ~]# echo $a
root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt operator:x:11:0:operator:/root:/sbin/nologin
[root@web ~]# b=$( echo "$a" | cut -d ":" -f3 )
您在 /var/spool/mail/root 中有邮件
[root@web ~]#
[root@web ~]# echo $b
0 5 6 7 11
[root@web ~]# vim user1.sh
[root@web ~]# vim user1.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS=read linesi;do
a=$( grep "0" "$lines" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b"=0 ];then
echo "$lines"
fi
done
[root@web ~]# chmod +x user1.sh
[root@web ~]# ./user1.sh
./user1.sh:行2: linesi: 未找到命令
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS=read linesi;do
a=$( grep "0" "$lines" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b"=0 ];then
echo "$lines"
fi
done
[root@web ~]# vim user1.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS=read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done
[root@web ~]# ./user1.sh
./user1.sh:行2: -r: 未找到命令
[root@web ~]# vim user1.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./user1.sh
^C您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim user1.sh
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done < user2.txt
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./user1.sh
grep: root:x:0:0:root:/root:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: bin:x:1:1:bin:/bin:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: daemon:x:2:2:daemon:/sbin:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: adm:x:3:4:adm:/var/adm:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: sync:x:5:0:sync:/sbin:/bin/sync: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: halt:x:7:0:halt:/sbin:/sbin/halt: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: mail:x:8:12:mail:/var/spool/mail:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: operator:x:11:0:operator:/root:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: games:x:12:100:games:/usr/games:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: nobody:x:99:99:Nobody:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: dbus:x:81:81:System message bus:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: polkitd:x:999:998:User for polkitd:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: libstoragemgmt:x:998:995:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: colord:x:997:994:User for colord:/var/lib/colord:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: saned:x:996:993:SANE scanner daemon user:/usr/share/sane:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: gluster:x:995:992:GlusterFS daemons:/run/gluster:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: saslauth:x:994:76:Saslauthd user:/run/saslauthd:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: abrt:x:173:173::/etc/abrt:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: radvd:x:75:75:radvd user:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: chrony:x:992:987::/var/lib/chrony:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: unbound:x:991:986:Unbound DNS resolver:/etc/unbound:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: qemu:x:107:107:qemu user:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: sssd:x:990:984:User for sssd:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: geoclue:x:989:983:User for geoclue:/var/lib/geoclue:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: ntp:x:38:38::/etc/ntp:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: gdm:x:42:42::/var/lib/gdm:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: postfix:x:89:89::/var/spool/postfix:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: tcpdump:x:72:72::/:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: caozx26:x:1000:1002:caozx26:/home/caozx26:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: XOAP:x:1002:1000::/rhome/XOAP:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: mysql:x:1003:1003::/home/mysql:/sbin/nologin: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: cao1:x:1004:1223::/home/cao1:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: cao2:x:1005:1005::/home/cao2:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: xiaocao:x:1006:1006::/home/xiaocao:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: xiao6:x:1007:1007::/home/xiao6:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: tom:x:1008:1008::/home/tom:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: jack:x:1009:1009::/home/jack:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: cw01:x:1010:1224::/home/cw01:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: sc01:x:1011:1226::/home/sc01:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: rs01:x:1012:1225::/home/rs01:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: boss01:x:1013:1004::/home/boss01:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: cw02:x:1014:1224::/home/cw02:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: sc02:x:1015:1226::/home/sc02:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: rs02:x:1016:1225::/home/rs02:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: harry:x:1017:1017::/home/mahei/redhat/harry:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: netasha:x:1018:1018::/home/netasha:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: sarsh:x:1019:1228::/home/sarsh:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: OOO:x:1020:1020::/home/OOO:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: jerry:x:1021:1229::/home/jerry:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: kefu:x:1022:1022::/home/kefu:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: kefu2:x:1023:1023::/home/kefu2:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: user01:x:1024:1024::/home/user01:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: u4:x:1025:1025::/home/u4:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: u1:x:1026:1026::/home/u1:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: u2:x:1027:1027::/home/u2:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: u3:x:1028:1028::/home/u3:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: u5:x:1029:1029::/home/u5:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: stu0:x:1030:1030::/rhome:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: stu1:x:1031:1031::/rhome:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: stu2:x:1032:1032::/rhome:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: stu3:x:1033:1033::/rhome:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: stu4:x:1034:1034::/rhome:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: stu5:x:1035:1035::/rhome:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: user1r0:x:1036:1036::/home/user1r0:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: user1r1:x:1037:1037::/home/user1r1:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: user1r2:x:1038:1038::/home/user1r2:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: user1r3:x:1039:1039::/home/user1r3:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: user1r4:x:1040:1040::/home/user1r4:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: useros20:x:1041:1041::/home/useros20:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: useros21:x:1042:1042::/home/useros21:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: useros22:x:1043:1043::/home/useros22:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: useros23:x:1044:1044::/home/useros23:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
grep: useros24:x:1045:1045::/home/useros24:/bin/bash: 没有那个文件或目录
./user1.sh: 第 5 行:[: : 期待整数表达式
[root@web ~]# cat userc.sh
cat: userc.sh: 没有那个文件或目录
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
a=$( grep ":0:" "$line" )
b=$( echo "$a"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line"
fi
done < user2.txt
[root@web ~]# vim user1.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
b=$( echo "$line"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line" >>root1.txt
fi
done < user2.txt
[root@web ~]# ./user1.sh
[root@web ~]# cat root1.txt
root:x:0:0:root:/root:/bin/bash
[root@web ~]# tail -5 user2.txt
useros20:x:1041:1041::/home/useros20:/bin/bash
useros21:x:1042:1042::/home/useros21:/bin/bash
useros22:x:1043:1043::/home/useros22:/bin/bash
useros23:x:1044:1044::/home/useros23:/bin/bash
useros24:x:1045:1045::/home/useros24:/bin/bash
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim user1.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
b=$( echo "$line"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line" >>root1.txt
elsif [ "$b" -gt 0 ] && [ "$b" -lt 1000 ];then
echo "$line" >> system12.txt
else [ "$b" -gt 1000 ];then
echo "$line" >> normal12.txt
fi
done < user2.txt
[root@web ~]# ./user1.sh
./user1.sh:行6: 未预期的符号 `then' 附近有语法错误
./user1.sh:行6: `elsif [ "$b" -gt 0 ] && [ "$b" -lt 1000 ];then'
[root@web ~]# vim user1.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1
user1c.sh  user1.sh
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
b=$( echo "$line"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line" >>root1.txt
elif [ "$b" -gt 0 ] && [ "$b" -lt 1000 ];then
echo "$line" >> system12.txt
elif [ "$b" -ge 1000 ];then
echo "$line" >> normal12.txt
fi
done < user2.txt
[root@web ~]# ./u
uc.sh        unameok.sh   up1.sh       url.sh       user1c.sh    useradd1.sh  userad.sh
uname2.sh    uname.sh     up2.sh       ur.sh        user1.sh     useradd.sh   user.sh
[root@web ~]# ./user1.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat user1.sh
cat /etc/passwd > user2.txt
while IFS= read -r line;do
b=$( echo "$line"| cut -d ":" -f3 )
if [ "$b" -eq 0 ];then
echo "$line" >>root1.txt
elif [ "$b" -gt 0 ] && [ "$b" -lt 1000 ];then
echo "$line" >> system12.txt
elif [ "$b" -ge 1000 ];then
echo "$line" >> normal12.txt
fi
done < user2.txt
[root@web ~]# cat system12.txt
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
libstoragemgmt:x:998:995:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
colord:x:997:994:User for colord:/var/lib/colord:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
saned:x:996:993:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
gluster:x:995:992:GlusterFS daemons:/run/gluster:/sbin/nologin
saslauth:x:994:76:Saslauthd user:/run/saslauthd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
chrony:x:992:987::/var/lib/chrony:/sbin/nologin
unbound:x:991:986:Unbound DNS resolver:/etc/unbound:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
sssd:x:990:984:User for sssd:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
geoclue:x:989:983:User for geoclue:/var/lib/geoclue:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@web ~]# cat normal12.txt
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
caozx26:x:1000:1002:caozx26:/home/caozx26:/bin/bash
XOAP:x:1002:1000::/rhome/XOAP:/bin/bash
mysql:x:1003:1003::/home/mysql:/sbin/nologin
cao1:x:1004:1223::/home/cao1:/bin/bash
cao2:x:1005:1005::/home/cao2:/bin/bash
xiaocao:x:1006:1006::/home/xiaocao:/bin/bash
xiao6:x:1007:1007::/home/xiao6:/bin/bash
tom:x:1008:1008::/home/tom:/bin/bash
jack:x:1009:1009::/home/jack:/bin/bash
cw01:x:1010:1224::/home/cw01:/bin/bash
sc01:x:1011:1226::/home/sc01:/bin/bash
rs01:x:1012:1225::/home/rs01:/bin/bash
boss01:x:1013:1004::/home/boss01:/bin/bash
cw02:x:1014:1224::/home/cw02:/bin/bash
sc02:x:1015:1226::/home/sc02:/bin/bash
rs02:x:1016:1225::/home/rs02:/bin/bash
harry:x:1017:1017::/home/mahei/redhat/harry:/bin/bash
netasha:x:1018:1018::/home/netasha:/bin/bash
sarsh:x:1019:1228::/home/sarsh:/bin/bash
OOO:x:1020:1020::/home/OOO:/bin/bash
jerry:x:1021:1229::/home/jerry:/bin/bash
kefu:x:1022:1022::/home/kefu:/bin/bash
kefu2:x:1023:1023::/home/kefu2:/bin/bash
user01:x:1024:1024::/home/user01:/bin/bash
u4:x:1025:1025::/home/u4:/bin/bash
u1:x:1026:1026::/home/u1:/bin/bash
u2:x:1027:1027::/home/u2:/bin/bash
u3:x:1028:1028::/home/u3:/bin/bash
u5:x:1029:1029::/home/u5:/bin/bash
stu0:x:1030:1030::/rhome:/bin/bash
stu1:x:1031:1031::/rhome:/bin/bash
stu2:x:1032:1032::/rhome:/bin/bash
stu3:x:1033:1033::/rhome:/bin/bash
stu4:x:1034:1034::/rhome:/bin/bash
stu5:x:1035:1035::/rhome:/bin/bash
user1r0:x:1036:1036::/home/user1r0:/bin/bash
user1r1:x:1037:1037::/home/user1r1:/bin/bash
user1r2:x:1038:1038::/home/user1r2:/bin/bash
user1r3:x:1039:1039::/home/user1r3:/bin/bash
user1r4:x:1040:1040::/home/user1r4:/bin/bash
useros20:x:1041:1041::/home/useros20:/bin/bash
useros21:x:1042:1042::/home/useros21:/bin/bash
useros22:x:1043:1043::/home/useros22:/bin/bash
useros23:x:1044:1044::/home/useros23:/bin/bash
useros24:x:1045:1045::/home/useros24:/bin/bash
[root@web ~]# now=$( date + %s )
date: 额外的操作数 "%s"
Try 'date --help' for more information.
您在 /var/spool/mail/root 中有邮件
[root@web ~]# date +%s
1756817203
[root@web ~]# date
2025年 09月 02日 星期二 20:46:46 CST
[root@web ~]# now=$( date +%s )
您在 /var/spool/mail/root 中有邮件
[root@web ~]# echo $now
1756817319
[root@web ~]# tar=2020-02-12
您在 /var/spool/mail/root 中有邮件
[root@web ~]# tar_seconds=( date -d "$tar" +%s )
您在 /var/spool/mail/root 中有邮件
[root@web ~]# echo $tar
$tar          $tar_seconds
[root@web ~]# echo $tar_seconds
date
[root@web ~]# tar_se=$( date -d "$tar" +%s )
您在 /var/spool/mail/root 中有邮件
[root@web ~]# echo $tar_se
1581436800
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [ $tar =~ ^[0-9]{0-4}-[0-9]{0-2}-{0-9}[0-2] ];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# chmod +x upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2024-12-22
./upt.sh: 第 2 行:[: =~: 期待二元表达式
wrong
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [ $tar =~ ^[0-9]{0-4}-[0-9]{0-2}-{0-9}[0-2]$ ];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# ./upt.sh
pl input a date:2024-2-12
./upt.sh: 第 2 行:[: =~: 期待二元表达式
wrong
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:1202-12-12
./upt.sh: 第 2 行:[: =~: 期待二元表达式
wrong
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{0-4}-[0-9]{0-2}-{0-9}[0-2]$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# ./u
uc.sh        uname.sh     upt.sh       user1c.sh    useradd.sh
uname2.sh    up1.sh       url.sh       user1.sh     userad.sh
unameok.sh   up2.sh       ur.sh        useradd1.sh  user.sh
[root@web ~]# ./upt.sh
pl input a date:2011-02-12
wrong
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-{0-9}[2]$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2023-02-12
wrong
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-{0-9}{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
day=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
agoday=$(( day * -1 ))
echo "$tar is $agoday ago"
else
echo "$tar is $agoday after"
fi
[root@web ~]# ./upt.sh
pl input a date:2012-12-21
2012-12-21 is -9260 ago
[root@web ~]# ./upt.sh
pl input a date:2032-12-21
2032-12-21 is  after
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
echo "$tar is $agoday ago"
else
day=$(( agoday * -1 ))
echo "$tar is $day  after"
fi
[root@web ~]# ./up
up1.sh  up2.sh  upt.sh
[root@web ~]# ./upt.sh
pl input a date:2011-09-12
2011-09-12 is 24386 ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:192-1-12
wrong
[root@web ~]# ./upt.sh
pl input a date:1292-12-12
1292-12-12 is 34374 ago
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se % 84200 ))
if [ "$cut_se" -gt 0 ];then
echo "$tar is $agoday day ago"
else
day=$(( agoday * -1 ))
echo "$tar is $day day after"
fi
[root@web ~]# ./
alll1/           for51.sh         okl/             stuc.sh          url.sh
app/             for5.sh          pho.sh           sum.sh           ur.sh
apr-1.5.2/       ftpok.sh         php-7.2.17/      test1.sh         user1c.sh
apr-util-1.5.4/  ftp.sh           ping2.sh         testcfor.sh      user1.sh
axel-2.4/        .gvfs/           ping.sh          testff1.sh       useradd1.sh
.cache/          httpd-2.4.37/    .pki/            testff.sh        useradd.sh
classfi.sh       id.sh            primeok.sh       testfor2.sh      userad.sh
code/            judgefn.sh       process1.sh      testfor3.sh      user.sh
.config/         judgeprimeok.sh  process.sh       testfor4.sh      vsftpd1.sh
cuser1.sh        judgeprime.sh    psok.sh          testforf.sh      vsftpd2.sh
.dbus/           kk/              pub/             testfor.sh       vsftpdins.sh
dn.sh            lc.sh            readme7          uc.sh            vsftpdok.sh
expect1.sh       .local/          readme.txt/      uname2.sh        vsftpd.sh
expect4.sh       logs/            rsa.sh           unameok.sh       vstest.sh
expect5c.sh      luck.sh          serverOk.sh      uname.sh         .wireshark/
expect5.sh       mysql-5.6.31/    service-s.sh     up1.sh           wordpress/
expect6.sh       num.sh           shift.sh         up2.sh           yearok.sh
expect.sh        ok/              .ssh/            upt.sh
[root@web ~]# ./upt.sh
pl input a date:1222-12-21
1222-12-21 is 18680 day ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se / 86400 ))
if [ "$cut_se" -gt 0 ];then
echo "$tar is $agoday day ago"
else
day=$(( agoday * -1 ))
echo "$tar is $day day after"
fi
[root@web ~]# ./upt.sh
pl input a date:2121-12-12
2121-12-12 is 35163 day after
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:1202-12-21
1202-12-21 is 300485 day ago
[root@web ~]# ./upt.sh
pl input a date:2012-12-21
2012-12-21 is 4638 day ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se / 86400 ))
ago_hours=$(( (agoday % 86400) /3600))
ago_minutes=$(((agoday %3600)/60))
ago_se=$((agoday % 60 ))
if [ "$cut_se" -gt 0 ];then
echo "$tar is $agoday day ago"
echo
else
day=$(( agoday * -1 ))
echo "$tar is $day day after"fi
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se / 86400 ))
ago_hours=$(( (agoday % 86400) /3600))
ago_minutes=$(((agoday %3600)/60))
ago_se=$(( agoday % 60 ))
if [ "$cut_se" -gt 0 ];then
echo ""$tar" is "$agoday"day "$ago_hours"h "$ago_minutes"min "$ago_se"s ago"
else
day=$(( agoday * -1 ))
hours=$(( ago_hours * -1 ))
minutes=$(( ago_minutes * -1 ))
se=$(( ago * -1 ))
echo ""$tar" is "$day"day "$hours"h "$minutes"m "$se"s after"fi
[root@web ~]# ./upt.sh
pl input a date:2012-12-21
2012-12-21 is 4638day 1h 17min 18s ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2033-12-22
2033-12-22 is 3032day 0h 50m 0s after
[root@web ~]# ./upt.sh
pl input a date:2092-12-10
2092-12-10 is 24570day 6h 49m 0s after
[root@web ~]# echo $a
root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt operator:x:11:0:operator:/root:/sbin/nologin
您在 /var/spool/mail/root 中有邮件
[root@web ~]# echo $now
1756817319
[root@web ~]# date
2025年 09月 02日 星期二 22:40:35 CST
[root@web ~]# a=$(date)
[root@web ~]# echo $a
2025年 09月 02日 星期二 22:40:59 CST
[root@web ~]# echo $a
2025年 09月 02日 星期二 22:40:59 CST
[root@web ~]# echo $a
2025年 09月 02日 星期二 22:40:59 CST
[root@web ~]# echo $a
2025年 09月 02日 星期二 22:40:59 CST
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se / 86400 ))
ago_hours=$((( cut_se % 86400) /3600))
ago_minutes=$(((cut_se %3600)/60))
ago_se=$(( cut_se % 60 ))
if [ "$cut_se" -gt 0 ];then
echo ""$tar" is "$agoday"day "$ago_hours"h "$ago_minutes"min "$ago_se"s ago"
else
day=$(( agoday * -1 ))
hours=$(( ago_hours * -1 ))
minutes=$(( ago_minutes * -1 ))
se=$(( ago * -1 ))
echo ""$tar" is "$day"day "$hours"h "$minutes"m "$se"s after"fi
[root@web ~]# ./upt.sh
pl input a date:2012-12-21
2012-12-21 is 4638day 22h 49min 46s ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2026-12-21
2026-12-21 is 474day 1h 4m 0s after
您在 /var/spool/mail/root 中有邮件
[root@web ~]# vim upt.sh
您在 /var/spool/mail/root 中有邮件
[root@web ~]# cat upt.sh
read -p "pl input a date:" tar
if ! [[ $tar =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then
echo "wrong"
exit 1
fi
now_se=$( date +%s )
tar_se=$( date -d $tar +%s )
cut_se=$(( now_se - tar_se ))
agoday=$(( cut_se / 86400 ))
ago_hours=$((( cut_se % 86400) /3600))
ago_minutes=$(((cut_se %3600)/60))
ago_se=$(( cut_se % 60 ))
if [ "$cut_se" -gt 0 ];then
echo ""$tar" is "$agoday"day "$ago_hours"h "$ago_minutes"min "$ago_se"s ago"
else
day=$(( agoday * -1 ))
hours=$(( ago_hours * -1 ))
minutes=$(( ago_minutes * -1 ))
se=$(( ago_se * -1 ))
echo ""$tar" is "$day"day "$hours"h "$minutes"m "$se"s after"fi
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2019-12-12
2019-12-12 is 2091day 23h 4min 48s ago
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2028-12-21
2028-12-21 is 1205day 0h 53m 28s after
您在 /var/spool/mail/root 中有邮件
[root@web ~]# ./upt.sh
pl input a date:2035-12-21
2035-12-21 is 3761day 0h 50m 5s after
您在 /var/spool/mail/root 中有邮件
[root@web ~]#
http://www.dtcms.com/a/363058.html

相关文章:

  • 【JavaEE】多线程案例
  • 删除⽂件之git
  • 前端20个高效开发的JS工具函数
  • 《水浒智慧》第二部“英雄是怎么炼成的”(下篇)读书笔记
  • 宋红康 JVM 笔记 Day11|直接内存
  • 怎么用redis lua脚本实现各分布式锁?Redisson各分布式锁怎么实现的?
  • Higress云原生API网关详解 与 Linux版本安装指南
  • lua脚本在redis中如何单步调试?
  • docker 安装 redis 并设置 volumes 并修改 修改密码(二)
  • MATLAB矩阵及其运算(四)矩阵的运算及操作
  • 互联网大厂求职面试记:谢飞机的搞笑答辩
  • Linux为什么不是RTOS
  • 对矩阵行化简操作几何含义的理解
  • 集群无法启动CRS-4124: Oracle High Availability Services startup failed
  • TSMC-1987《Convergence Theory for Fuzzy c-Means: Counterexamples and Repairs》
  • uni-app 实现做练习题(每一题从后端接口请求切换动画记录错题)
  • Nginx的反向代理与正向代理及其location的配置说明
  • 久等啦!Tigshop O2O多门店JAVA/PHP版本即将上线!
  • SpringBoot3 + Netty + Vue3 实现消息推送(最新)
  • B树和B+树,聚簇索引和非聚簇索引
  • 云计算学习100天-第44天-部署邮件服务器
  • vscode炒股插件-韭菜盒子AI版
  • 小白H5制作教程!一分钟学会制作企业招聘H5页面
  • Linux 环境配置 muduo 网络库详细步骤
  • WPF 开发必备技巧:TreeView 自动展开全攻略
  • gbase8s之导出mysql导入gbase8s
  • WebSocket STOMP协议服务端给客户端发送ERROR帧
  • 串口服务器技术详解:2025年行业标准与应用指南
  • 大文件稳定上传:Spring Boot + MinIO 断点续传实践
  • DevOps部署与监控