目录
1. 运行脚本可以显示出本机的ip地址
2. 如果ip地址中有3这个数字,那么就打印出当前的系统时间
3. 如果ip地址中不含3这个数字,就批量建立用户magedu_00, magedu_01, ... magedu_100并且所有用户同属于magedu组
4. 打印出/etc/passwd这个文件中可以登陆的用户(非/usr/sbin/nologin)
5. yum安装nginx服务,并且启动该服务
6. 一个脚本完成
获取ip地址代码如下:
#!/bin/bash #设置命令解释器ipaddr=`ifconfig eth0|head -n 2|tail -n 1|tr -s " " |cut -d " " -f3` #获取本机ip地址echo $ipaddr #打印ip地址
#!/bin/bashipaddr=`ifconfig eth0|head -n 2|tail -n1|tr -s " " |cut -d " " -f3`echo $ipaddrif echo $ipaddr | grep '3';then echo $(date +%F%n%T)fi
#!/bin/bashipaddr=`ifconfig eth0|head -n 2|tail -n1|tr -s " " |cut -d " " -f3`echo $ipaddrif echo $ipaddr | grep '3';then echo $(date +%F%n%T)else for a in{00..100};do useradd magedu_$a -g magedudonefi
查询/etc/passwd文件内容
执行命令:cat -n /etc/passwd
[root@administrator /]# cat -n /etc/passwd 1root:x:0:0:root:/root:/bin/bash 2bin:x:1:1:bin:/bin:/sbin/nologin 3daemon:x:2:2:daemon:/sbin:/sbin/nologin 4adm:x:3:4:adm:/var/adm:/sbin/nologin 5lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 6sync:x:5:0:sync:/sbin:/bin/sync 7shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 8halt:x:7:0:halt:/sbin:/sbin/halt 9mail:x:8:12:mail:/var/spool/mail:/sbin/nologin 10operator:x:11:0:operator:/root:/sbin/nologin 11games:x:12:100:games:/usr/games:/sbin/nologin 12ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin 13nobody:x:99:99:Nobody:/:/sbin/nologin 14systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin 15dbus:x:81:81:System message bus:/:/sbin/nologin 16polkitd:x:999:998:User for polkitd:/:/sbin/nologin 17sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 18postfix:x:89:89::/var/spool/postfix:/sbin/nologin 19tom:x:1000:1000:tom:/home/tom:/bin/bash 20tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin 21ntp:x:38:38::/etc/ntp:/sbin/nologin 22tcpdump:x:72:72::/:/sbin/nologin 23chrony:x:998:996::/var/lib/chrony:/sbin/nologin 24apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
打印文件中可以登陆的用户(非/usr/sbin/nologin)
执行命令:cat -n /etc/passwd | grep -v /sbin/nologin
[root@administrator /]# cat -n /etc/passwd | grep -v /sbin/nologin 1root:x:0:0:root:/root:/bin/bash 6sync:x:5:0:sync:/sbin:/bin/sync 7shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 8halt:x:7:0:halt:/sbin:/sbin/halt 19tom:x:1000:1000:tom:/home/tom:/bin/bash
yum安装nginx服务
执行命令:yum -y install nginx
[root@administrator ~]# yum -y install nginxRocky Linux 8 - AppStream 4.4 kB/s | 4.8 kB 00:01 Rocky Linux 8 - BaseOS 1.5 kB/s | 4.3 kB 00:02 Rocky Linux 8 - Extras 2.5 kB/s | 3.5 kB 00:01 Dependencies resolved.============================================================================================================================== Package Architecture Version Repository Size==============================================================================================================================Installing: nginx x86_64 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 566 k# #省略安装详情Complete! #安装完成了
查看服务启动状态方式一:
启动该服务,默认端口80
执行代码:systemctl start nginx
监听80端口是否开启,如80端口监听成功,则该服务开启成功
[root@administrator ~]# systemctl start nginx[root@administrator ~]# ss -ntulNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process udp UNCONN 0 0 127.0.0.1:323 0.0.0.0:* udp UNCONN 0 0 [::1]:323 [::]:* tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* tcp LISTEN 0 128 [::]:80 [::]:* tcp LISTEN 0 128 [::]:22 [::]:*
查看服务启动状态方式二:
或者查看nginx服务启动状态
执行命令:systemctl status nginx
#!/bin/bashipaddr=`ifconfig eth0|head -n 2|tail -n1|tr -s " " |cut -d " " -f3`echo $ipaddrif echo $ipaddr | grep '3';then echo $(date +%F%n%T)else for a in{00..100};do useradd magedu_$a -g magedudonefi
留言与评论(共有 0 条评论) “” |