包含标签 Linux articles

linux cron表达式

解析crontab表达式的网站:https://crontab.guru/

Cron是什么?

简单来讲,cron是基于Unix的系统上的一个实用程序。它使用户能够安排任务在指定的【日期/时间】定期运行。它自然是一个伟大的工具,可以自动运行大量流程,不需要人工干预。

Cron作为守护进程运行。这意味着它只需要启动一次,并将在后台继续运行。此过程使用crontab读取计划条目并启动任务。

……

Continue reading

ASCII码表

ASCII码,使用7位二进制数,表示128个标准ASCII字符,使用8位二进制数,表示256 个标准及扩展ASCII字符;

ASCII编码字符分类:

控制字符:0~32、127表示,共33个,如CR(回车)、LF(换行)、FF(换页)、BS(退格)、DEL(删除)、Space(空格)等。

特殊符号:33-47表示,如+(加)、-(减)、*(乘)、/(除)、!(感叹号)。

……

Continue reading

iptables的数据包的流程介绍

参考:https://www.linuxso.com/linuxpeixun/10330.html

iptables的数据包的流程介绍

iptables 相关概念

匹配(match):符合指定的条件,比如指定的 IP 地址和端口。

丢弃(drop):当一个包到达时,简单地丢弃,不做其它任何处理。

接受(accept):和丢弃相反,接受这个包,让这个包通过。

……

Continue reading

linux cat

利用cat 给文件写内容,追加的方式

1
2
3
4
cat >> proxy.sh <<EOF
export http_proxy=http://99.0.85.1:808
export https_proxy=http://99.0.85.1:808
EOF

cat给文件写内容,覆盖的方式

1
2
3
4
cat > proxy.sh <<EOF
export http_proxy=http://99.0.85.1:808
export https_proxy=http://99.0.85.1:808
EOF
……

Continue reading

sed替换命令收集

普通操作可以使用冒号(:)井号(#)正斜杠(/)来作为分隔符

1
2
3
4
5
sed -i 's#abc#def#g'  a.file  #将文件a.file中的abc替换成def
sed -i 's/^abc.*/abc=def/' a.file # 将a.file中以abc开头的一行替换成abc=def
sed -i '/ABC/,$d' a.file # 将a.file中从ABC开始(包括ABC)以后的所有行删除
sed -i '$a aabbccdd' a.file # 给a.file追加aabbccdd
cat geng.file | sed  's/abc/def/g'   ## 打印文件geng,并将其中的abc替换成def

参考:https://blog.csdn.net/genghongsheng/article/details/120432010

……

Continue reading

cgroup

参考:https://zhuanlan.zhihu.com/p/434731896、https://www.cnblogs.com/zhrx/p/16388175.html

cgroup

目前我们所提到的容器技术、虚拟化技术(不论何种抽象层次下的虚拟化技术)都能做到资源层面上的隔离和限制。

对于容器技术而言,它实现资源层面上的限制和隔离,依赖于linux内核所提供的cgroup和namespace技术。

……

Continue reading

linux自动化交互工具:expect示例

安装

1
yum -y install expect

使用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/expect
# 本脚本需要安装 
# yum -y install expect
# yum install rsync -y

# 该脚本的作用为将指定名称的文件同步到其他节点
# params
# fname: 要同步的文件名
# hostip:目的节点
# user:目的节点用户名
# passwd:目的节点密码

# 设置变量
set fname [lindex $argv 0]
set hostip  [lindex $argv 1]
set user [lindex $argv 2]
set passwd [lindex $argv 3]
puts "fname=$fname"
puts "hostip=$hostip"
puts "user=$user"
puts "passwd=$passwd"

spawn rsync -rvl $fname $user@$hostip:/root/
expect {
 "*yes/no" {send "yes\r";exp_continue}
 "*password*:" {send "$passwd\r"}
}

expect eof
……

Continue reading

建立一个名为agetest的账号,该账号第一次登陆后使用默认密码,但必须更改密码后使用新密码才能够登陆系统使用bash环境

建立一个名为agetest的账号,该账号第一次登陆后使用默认密码,但必须更改密码后使用新密码才能够登陆系统使用bash环境。

增加用户agetest,且设置初始密码和用户名保持一致

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[root@centos dashboard]# useradd agetest
[root@centos dashboard]# echo "agetest" | passwd --stdin agetest
Changing password for user agetest.
passwd: all authentication tokens updated successfully.
[root@centos dashboard]# chage -d 0 agetest
[root@centos dashboard]# chage -l agetest | head -n 3
Last password change					: password must be changed
Password expires					: password must be changed
Password inactive					: password must be changed
[root@centos dashboard]# logout

使用agetest登陆linux,便会强制让用户更改密码

……

Continue reading

解压缩

最简单的使用tar的命令:

1
2
3
4
5
6
7
8
# 压缩
tar -jcv -f filename.tar.bz2 要被压缩的文件或目录名称

# 查询
tar -jtv -f filename.tar.bz2

# 解压缩
tar -jxv -f filename.tar.bz2 -C 欲解压缩的目录
……

Continue reading