#!/bin/bash
#显示出本机的ip地址方法一
#ip a|grep dynamic|tr -s ' ' \/|cut -d'/' -f3
#显示出本机的ip地址方法二
ip a|sed -rn 's/(.*inet )([0-9].*)(\/[0-9].*)( brd.*)/\2/p'
#显示出本机ip地址方法三
#hostname -I
#把ip地址赋值给变量ipaddr,上述三种方法均可
ipaddr=`ip a|grep dynamic|tr -s ' ' \/|cut -d'/' -f3`
#判断ip地址是否含有3
echo $ipaddr|grep 3 &>/dev/null
#把ip地址是否含有3的结果赋值给变量contain_3
contain_3=`echo $?`
if (($contain_3 == 0));
then
echo `date +%Y-%T`;
else
groupadd magedu
#批量建立用户magedu_00, magedu_01, ... magedu_100并且所有用户同属于magedu组,方法一
#echo magedu_{00..100} |xargs -n1 useradd -g magedu
#批量建立用户magedu_00, magedu_01, ... magedu_100并且所有用户同属于magedu组,方法二
for i in {00..100};do useradd magedu_$i -g magedu;
done
fi
#cat /etc/passwd |grep -v /sbin/nologin
#上述方法打印出/etc/passwd这个文件中可以登陆的用户(非/usr/sbin/nologin)(含/etc/passwd的其他用户信息)
cat /etc/passwd |grep -v /sbin/nologin|awk -F ':' '{print $1}'
#上述方法打印出/etc/passwd这个文件中可以登陆的用户(非/usr/sbin/nologin)(单纯只含有用户名)
cat >>/etc/yum.repos.d/CentOS-Base.repo << EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64/
gpgcheck=0
enabled=1
EOF
yum clean all
yum makecache
yum -y install nginx
systemctl start nginx
systemctl status nginx
执行结果
1.显示出本机的ip地址方法一、二、三
[root@localhost ~]# ip a|grep dynamic|tr -s ' ' \/|cut -d'/' -f3
20.0.0.129
[root@localhost ~]# ip a|sed -rn 's/(.*inet )([0-9].*)(\/[0-9].*)( brd.*)/\2/p'
20.0.0.129
[root@localhost ~]# hostname -I
20.0.0.129
2.批量建立用户magedu_00, magedu_01, ... magedu_100并且所有用户同属于magedu组,方法一、二
echo magedu_{00..100} |xargs -n1 useradd -g magedu
for i in {00..100};do useradd magedu_$i -g magedu;
done
fi
3.脚本整体运行
[root@localhost ~]# bash secweek.sh
20.0.0.129
root
sync
shutdown
halt
cqz
magedu_000
magedu_001
magedu_002
magedu_003
magedu_004
magedu_005
magedu_006
magedu_007
magedu_008
magedu_009
magedu_010
magedu_011
magedu_012
magedu_013
magedu_014
magedu_015
magedu_016
magedu_017
magedu_018
magedu_019
magedu_020
magedu_021
magedu_022
magedu_023
magedu_024
magedu_025
magedu_026
magedu_027
magedu_028
magedu_029
magedu_030
magedu_031
magedu_032
magedu_033
magedu_034
magedu_035
magedu_036
magedu_037
magedu_038
magedu_039
magedu_040
magedu_041
magedu_042
magedu_043
magedu_044
magedu_045
magedu_046
magedu_047
magedu_048
magedu_049
magedu_050
magedu_051
magedu_052
magedu_053
magedu_054
magedu_055
magedu_056
magedu_057
magedu_058
magedu_059
magedu_060
magedu_061
magedu_062
magedu_063
magedu_064
magedu_065
magedu_066
magedu_067
magedu_068
magedu_069
magedu_070
magedu_071
magedu_072
magedu_073
magedu_074
magedu_075
magedu_076
magedu_077
magedu_078
magedu_079
magedu_080
magedu_081
magedu_082
magedu_083
magedu_084
magedu_085
magedu_086
magedu_087
magedu_088
magedu_089
magedu_090
magedu_091
magedu_092
magedu_093
magedu_094
magedu_095
magedu_096
magedu_097
magedu_098
magedu_099
magedu_100
Loaded plugins: fastestmirror
Cleaning repos: base extras nginx updates
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
nginx | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/13): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/13): extras/7/x86_64/filelists_db | 303 kB 00:00:00
(3/13): extras/7/x86_64/other_db | 150 kB 00:00:00
(4/13): base/7/x86_64/other_db | 2.6 MB 00:00:01
(5/13): extras/7/x86_64/primary_db | 250 kB 00:00:01
(6/13): base/7/x86_64/primary_db | 6.1 MB 00:00:01
(7/13): nginx/primary_db | 85 kB 00:00:00
(8/13): nginx/other_db | 53 kB 00:00:00
(9/13): updates/7/x86_64/other_db | 1.4 MB 00:00:01
(10/13): nginx/filelists_db | 110 kB 00:00:03
(11/13): updates/7/x86_64/filelists_db | 12 MB 00:00:03
(12/13): base/7/x86_64/filelists_db | 7.2 MB 00:00:24
(13/13): updates/7/x86_64/primary_db | 22 MB 00:00:54
Metadata Cache Created
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.24.0-1.el7.ngx will be installed
--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: 1:nginx-1.24.0-1.el7.ngx.x86_64
--> Running transaction check
---> Package pcre2.x86_64 0:10.23-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================
Installing:
nginx x86_64 1:1.24.0-1.el7.ngx nginx 804 k
Installing for dependencies:
pcre2 x86_64 10.23-2.el7 base 201 k
Transaction Summary
=================================================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 1.0 M
Installed size: 3.3 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/pcre2-10.23-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for pcre2-10.23-2.el7.x86_64.rpm is not installed
(1/2): pcre2-10.23-2.el7.x86_64.rpm | 201 kB 00:00:00
(2/2): nginx-1.24.0-1.el7.ngx.x86_64.rpm | 804 kB 00:00:21
---------------------------------------------------------------------------------------------------------------------------------
Total 47 kB/s | 1.0 MB 00:00:21
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pcre2-10.23-2.el7.x86_64 1/2
Installing : 1:nginx-1.24.0-1.el7.ngx.x86_64 2/2
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* https://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* https://nginx.com/products/
----------------------------------------------------------------------
Verifying : pcre2-10.23-2.el7.x86_64 1/2
Verifying : 1:nginx-1.24.0-1.el7.ngx.x86_64 2/2
Installed:
nginx.x86_64 1:1.24.0-1.el7.ngx
Dependency Installed:
pcre2.x86_64 0:10.23-2.el7
Complete!
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2023-07-09 20:52:08 CST; 5ms ago
Docs: http://nginx.org/en/docs/
Process: 2245 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 2246 (nginx)
CGroup: /system.slice/nginx.service
├─2246 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─2247 nginx: worker process
Jul 09 20:52:08 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
Jul 09 20:52:08 localhost.localdomain systemd[1]: Can't open PID file /var/run/nginx.pid (yet?) after start: No such file...ctory
Jul 09 20:52:08 localhost.localdomain systemd[1]: Started nginx - high performance web server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
标签:00,shell,x86,magedu,nginx,64,Linux,第二篇,el7
From: https://www.cnblogs.com/chenqizhi/p/17539375.html