首页 > 系统相关 >Linux,shell入门,第二篇

Linux,shell入门,第二篇

时间:2023-07-09 21:14:15浏览次数:35  
标签:00 shell x86 magedu nginx 64 Linux 第二篇 el7

#!/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

相关文章

  • linux shell template
    Replaceenvironmentvariablesinafilewiththeiractualvalues?#config.xml<property><name>instanceId</name><value>$INSTANCE_ID</value></property><property><name>rootPath</name>......
  • linux常用命令
    1.linux常用命令1.1简介Linux_百度百科(baidu.com)1.2虚拟机相关安装:虚拟机安装linux,这里不做介绍登录:如果是root,提示符为#,普通用户则为$退出:logout重启:reboot关机:halt1.3linux文件系统了解即可linux下一切皆是文件目录结构1.3.1 目录说明 /:为跟目录/bin:b......
  • Linux相关概念及操作
    目录linux的文件系统是采用级层式的树状目录结构,在此结构中的最上层是根目录“/”,然后在此目录下再创建其他的目录。1./bin是Binary的缩写,这个目录存放着最经常使用的命令2./opt这是给主机额外安装软件所存放的目录。如安装ORACLE数据库就可放到该目录下。默认为空3./boot......
  • Linux 切换用户及环境变量的问题
    背景前几天用Linux的时候遇到一个问题,使用su切换用户时,用户已经切换了,但是环境变量却还是原来用户的,导致命令执行不了。现象首先,用普通用户登录Linux,运行echo$PATH:square@debian:~$whoamisquaresquare@debian:~$echo$PATH/home/square/.local/bin:/usr/local/bin:/usr/......
  • linux LVS+Keepalived
    keepalived服务主要用来做高可用,高可用在企业中是非常重要的技术,避免数据丢失和服务停止。目录一、keepalived概述二、keepalived实验原理三、keepalived模块四、实验演示五、总结        一、keepalived概述  1.keepalived服务重要功能......
  • shell 变量多行原样输出,支持\n 回车换行
    假设:git的commit提交说明是多行内容,要给一个变量。但要保持原来样式,比如原来是是3行,在变量输出时候也是3行。经验:要想原样显示,就要在变量上加双引号;单引号和不加会显示成一行。1.原始样式:gitlog-1--format="%B"2.内容给shell变量a:a_test=$(gitlog-1--for......
  • [PowerShell]设置笔记本亮度 -- CIM cmdlet
    如下:$monitor=Get-CimInstance-Namespaceroot/WMI-ClassNameWmiMonitorBrightnessMethodsInvoke-CimMethod-InputObject$monitor-MethodNamewmisetBrightness-Arguments@{Timeout='10';Brightness='25'}参考https://learn.microsoft.com......
  • Linux 使用 dup2 无法正常重定向管道 tinyhttpd
    项目地址:https://github.com/pphboy/pihttpd文件p_sys.ctinyhttpd是这样写的但是文档是,旧的在前,新在后intdup2(intoldfd,intnewfd);所以是,才能正常输出和输入dup2(1,in_pipe[1]);dup2(0,out_pipe[0]);......
  • 扫描linux系统磁盘占用,释放空间的免费工具
    如何查找linux系统的磁盘占用,扫描大文件,释放空间,可以使用免费工具ncdu。虽然有du和df命令可以查询磁盘和文件夹的大小,但毕竟不方便,不能扫描整个磁盘的情况。用ncdu命令更直观,可以按目录以树形显示每个文件夹的大小,找到占空间的文件或者文件夹,删除释放磁盘空间。并且扫描速度飞快......
  • Linux命令行/终端连接(隐藏)SSID的WiFi
    推荐看完Linux命令行/终端连接隐藏SSID的WiFi(续篇)和本文后,再按照实际情况采用network-manager或者ifupdown多数Linux系统默认自带有线网络的驱动和配置软件,但是对于WiFi则可能会缺少固件和相关软件。在此使用Debian11为例(Ubuntu也可),使用nmcli连接隐藏SSID的WiFi网络。无线网卡......