分类 linux 下的文章

daily_nohup.sh

#!/bin/bash
echo -e "\n\033[0;34m ----- 最近10行记录情况 ----- \033[0m\n"
cat nohup.out | tail -n 10
cat nohup.out >> bak_nohup_`date +%Y-%m-%d_%H%i%s`.out
echo "----- "`date +%Y-%m-%d`" -----\n" > nohup.out
echo -e "\n\033[0;32m ----- 剩余记录 ----- \033[0m\n"
cat nohup.out | tail -n 10

编写 xxx.sh
[root@localhost ~]# vim xxx.sh
#!/bin/bash
php bin/hyperf.php start

# 后台执行脚本
[root@localhost ~]# nohup ./sh_hyperf1.sh &

# 查看输出信息
[root@localhost ~]# cat nohup.out

# 查看后台运行的bash脚本
[root@localhost ~]# ps aux | grep bash

# 查看命令的最后100行输出
[root@localhost hyperf]# cat nohup.out | tail -n 100

# 查看占用9501端口的进程
[root@localhost hyperf]# lsof -i :9501
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php     10337 root    7u  IPv4  66249      0t0  TCP *:9501 (LISTEN)
php     10337 root   30u  IPv4  67042      0t0  TCP localhost.localdomain:9501->192.168.56.1:cp-spxdpy (ESTABLISHED)

# 按天备份


1. &

功能:加在一个命令的最后,可以把这个命令放在后台执行

2. nohup

如果让程序始终在后台执行,即使关闭当前的终端也执行(之前的&做不到),这时候需要nohup。该命令可以在你退出帐户/关闭终端之后继续运行相应的进程。关闭中断后,在另一个终端jobs已经无法看到后台跑得程序了,此时利用ps(进程查看命令)

linux tar.gz zip 解压缩 压缩命令

-------------------- tar --------------------

打包命令tar
tar -cvf 打包文件名 源文件
option:
    -c: 打包
    -v: 显示过程
    -f: 指定打包后的文件名
    -z: 压缩为.tar.gz格式
example:
    tar -cvf xxxx.tar xxxx
    tar -zxvf 压缩包名.tar.gz 源文件
压缩文件列表和目录到ddd.tar
tar -cvf public/ddd.tar .env vendor composer.lock 
压缩文件列表(包含软链的实际文件)和目录到ddd.tar
tar -hcvf public/ddd.tar .env vendor composer.lock 


解压example:
    tar -zxvf file.tar.gz
    tar -jxvf file.tar.bz2
    tar -jxvf file.tar.bz2 -C /tmp/ # 指定解压缩位置
    tar -zcvf xx1.tar.gz xx1 xx2 xx3 # 压缩多个文件
    tar -ztvf xxx.tar.gz # 只是查看压缩文件, 不解压

  • 最小安装centos8
在安装页面启用了网络连接, 然后安装好了后就直接进入了系统
  • 无法使用ifconfig命令
yum install net-tools -y
  • 无法使用ssh客户端连接
yum install openssh-server -y
安装好了后配置一下
vi /etc/ssh/sshd_config
把其中的 #Port 22 前面的 # 去掉
默认是允许root远程登录的, 如果需要关闭, PermitRootLogin yes 把其中的yes改为no即可
执行 /bin/systemctl start sshd.service 开启ssh服务, 这个命令没有回显

检查ssh服务是否开启
[root@localhost ~]# ps -e | grep sshd
 1223 ?        00:00:00 sshd
 2168 ?        00:00:00 sshd
 2172 ?        00:00:00 sshd

检查22号端口是否开启
[root@localhost ~]# netstat -an | grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0     52 192.168.56.102:22       192.168.56.1:4777       ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN     

我这边测试默认好像是开机启动这个服务的, 如果没有开机自启
systemctl enable sshd.service