计划任务
2020年3月29日
9:25
1 | at | 一次性的计划计划任务 | |
2 | | crontab | 周期性的计划任务 |
at
创建 | |
at now+5min | 五分钟后执行 |
at 2020-03-30 | 在2020-03-30的该时间点进行执行 |
at 7am 2020-03-30 | 指定具体的时间和日期,去执行任务 |
at 8am+10days | 十天之后去执行计划任务 |
at now+2weeks | 两周之后去执行计划任务 |
warning: commands will be executed using /bin/sh
at> echo "hello TengkeEDU" | 要执行的命令 |
at> <EOT> | ctrl+D |
job 1 at Sun Mar 29 14:50:00 2020
查看计划任务的信息 | atq 管理员可以看到 所有用户的计划任务 普通用户 只能看到自己的计划人任务 |
at -l | |
查看具体的,查看文件 | [root@localhost spool]# cd /var/spool/at/ 只有管理员有权限去查看 如果管理员/普通用户想查看自己的计划任务 具体信息 at -c 编号 |
删除特定编号的计划任务 | atrm 3 管理员 可以删除所有用户的计划任务 普通用户 只能删除自己的计划任务 |
不希望 普通用户去做计划任务 | [root@localhost at]# vim /etc/at.deny |
希望 普通用户去做计划任务 | (1)删除/etc/at.deny中的用户名字 (2)白名单/etc/at.allow(事先不存在),允许优先 vim /etc/at.allow 后续用户 做计划任务的时候,会去检查 是否在白名单中存在,不存在 不能创建 |
注意 | 去安装邮件服务--- yum list postfix |
crontab | 周期性的计划任务 |
创建计划任务 | crontab -e -u user1 |
删除(全删除) | crontab -r |
删除一条 | crontab -e |
vim /var/spool/cron/user1 |
分 | 时 | 天(几号) | 月份 | 周(星期) | 执行命令 | |
每天15:36打印hello | 36 | 15 | * | * | * | echo "hello" |
7:00,7:10,7:30 | 0,10,30 | 7 | * | * | * | echo "ok" |
7:00 ~ 7:15 每五分钟 | 0-15/5 | 7 | * | * | * | |
周一到周五 7:00 ~ 7:15 每五分钟 | 1,2,3,4,5 | |||||
1-5 | ||||||
偶数月执行 | 0 | 7 | * | 2,4,6,8,10,12 2-12/2 | 1-3,6 | |
1月到6月,1-10号或1-5 执行 7:00 | 0 | 7 | 1-10 | 1-6 | 1-5 |
分 & 时 & 月 & (天 | 周)
上网四要素 | IP地址、掩码、网关、DNS(考官设备的IP地址) |
查看IP地址 | ifconfig | RHEL6:eth1、RHEL7:eno16777736,RHEL8:ens160 |
(1)图形化界面、tui、nm-connection-editor & | ||
(2)命令行--nmcli的命令 [root@localhost ~]# nmcli connection show NAME(逻辑名字) UUID TYPE DEVICE(物理名字) ens160 2aca5006-5656-4002-a06d-f88c38b0af9d ethernet ens160 ens444 011f3a08-fdc9-4770-b7ba-afa2975a08ad ethernet ens224 查看详细信息 [root@localhost ~]# nmcli connection show ens444 [root@localhost ~]# nmcli connection show ens444 | grep ipv4 通过逻辑连接--断开连接 [root@localhost ~]# nmcli connection down ens444 通过逻辑连接--启动连接 [root@localhost ~]# nmcli connection up ens444 通过物理设备--断开连接 [root@localhost ~]# nmcli device disconnect ens224 通过物理设备--启动连接 [root@localhost ~]# nmcli device connect ens224 修改 [root@localhost ~]# nmcli connection modify id ens444 connection.id ens666 nmcli connection modify id 连接的名字 修改的属性 新名字 [root@localhost ~]# nmcli connection modify ens666 connection.autoconnect yes 删除 [root@localhost ~]# nmcli connection delete ens666 创建新的连接 [root@localhost ~]# 56 创建一个connection叫做 tkedu888的连接,模式是 以太网,网络可用时自动启动、给nmcli connection add con-name tkedu888 type ethernet autoconnect yes ifname ens2ens256网卡去使用 可以自动的获取,默认 获取IP地址的方式是DHCP 手动配置IP地址(先配置IP地址,再修改模式) 两下tab键 nmcli connection modify tkedu888 ipv4.addresses "192.168.127.88/24" nmcli connection modify tkedu888 ipv4.gateway "192.168.127.2" nmcli connection modify tkedu888 ipv4.dns "8.8.8.8" nmcli connection modify tkedu888 ipv4.method manual 能不能先修改 manual 再配置IP地址 一个网卡需要多个IP地址 nmcli connection modify tkedu888 ipv4.addresses "192.168.127.88/24" (只保留一个IP地址) nmcli connection modify tkedu888 +ipv4.addresses "192.168.127.88/24" 删除特定的IP地址 [root@localhost ~]# nmcli connection modify tkedu888 -ipv4.addresses "192.168.127.188/24" 重启网络服务 [root@localhost ~]# systemctl restart network 安装network-scripts-10.00.1-1.el8.x86_64.rpm软件 如果说对网络修改了 [root@localhost ~]# nmcli connection down tkedu888 [root@localhost ~]# nmcli connection up tkedu888 加载所有的连接 [root@localhost ~]# nmcli connection reload |
1.桥接模式:这种模式下,虚拟机和物理机连的是同一个网络,虚拟机和物理机是并列关系,地位是相当的。比如,你家有路由器,那么你的电脑和你的手机同时连接这个路由器提供的Wi-Fi,那么它们的关系就是这种模式。
2.NAT模式:这种模式下,物理机会充当一个“路由器”的角色,虚拟机要想上网,必须经过物理机,那物理机如果不能上网,虚拟机也就不能上网了。之所以说这种模式兼容性最好,是因为物理机的网络环境变化时,虚拟机的网络并不会有影响,比如,上班时你把物理机连接在公司的网络环境中,下班后又把物理机连接在你家的路由器上。你公司的网段有可能和你家的网段是不同的。桥接模式下,虚拟机和物理机一样,都要自动获取IP才可以上网,而做实验的时候,是需要把虚拟机设置为静态IP的,这样就导致虚拟机网络不稳定。而设置为NAT模式,虚拟机的网络并不需要依赖你公司的网络环境或者你家的网络环境。
3.仅主机模式:这种模式下,相当于拿一根网线直连了物理机和虚拟机。
--------------------- vim ifcfg-ens21
这边必须在管理员视图下进行操作。
Nmcli connection reload
归档(tar)和压缩(zip、gzip、bzip)
2020年3月29日
9:25
归档 | 打包 | 箱子+实际东西 | 整个文件是变大 |
压缩 | 体积减少 | 整个文件是变小 |
实验准备 | [root@localhost tmp]# rm -rf * [root@localhost tmp]# ls [root@localhost tmp]# mkdir tkedu [root@localhost tmp]# ls tkedu [root@localhost tmp]# ls -l tkedu/ total 0 [root@localhost tmp]# cp /etc/passwd /etc/shadow tkedu/ [root@localhost tmp]# ls -l tkedu/ total 8 -rw-r--r--. 1 root root 2487 Mar 29 10:58 passwd ----------. 1 root root 1308 Mar 29 10:58 shadow [root@localhost tmp]# ls -lh tkedu/ total 8.0K -rw-r--r--. 1 root root 2.5K Mar 29 10:58 passwd ----------. 1 root root 1.3K Mar 29 10:58 shadow | ||||||||||||||
归档 |
|
压缩 | gzip、bzip2、zip |
1 | 实验准备 | [root@localhost tkedu]# dd if=/dev/zero of=file bs=1M count=100 |
2 | gzip--gz | [root@localhost tkedu]# gzip file [root@localhost tkedu]# ll -h total 100K -rw-r--r--. 1 root root 100K Mar 29 11:17 file.gz 压缩之后,源文件自动删除,并且 生成 以gz结尾的文件 解压缩 -d [root@localhost tkedu]# gzip -d file.gz [root@localhost tkedu]# ll -h total 100M -rw-r--r--. 1 root root 100M Mar 29 11:17 file 解压之后,压缩文件自动删除 查看文件属性 [root@localhost tkedu]# file file.gz file.gz: gzip compressed data |
3 | bzip--bz2 | [root@localhost tkedu]# bzip2 file [root@localhost tkedu]# ll -h total 4.0K -rw-r--r--. 1 root root 113 Mar 29 11:17 file.bz2 [root@localhost tkedu]# bzip2 -d file.bz2 查看文件属性 [root@localhost tkedu]# file file.bz2 file.bz2: bzip2 compressed data, |
4 | zip | [root@localhost tkedu]# zip file.zip file 压缩之后,源文件不删除 [root@localhost tkedu]# unzip file.zip 解压的时候,压缩文件不删除 查看信息 [root@localhost tkedu]# file file.zip file.zip: Zip archive data |
归档和压缩的使用
归档+压缩 | tar -cvf 归档文件名字 归档文件 |
解档+解压缩 | tar -xvf 需要解档的文件 |
-z | gzip | [root@localhost tkedu]# tar --help | grep gzip tar -zcvf 归档文件名字 归档文件 tar -zxvf 需要解档的文件 |
-j | bzip | [root@localhost tkedu]# tar --help | grep bzip tar -jcvf 归档文件名字 归档文件 tar -jxvf 需要解档的文件 |
实验准备 | [root@localhost tkedu]# cp /etc/passwd /etc/shadow /etc/services . |
归档+gzip压缩 tar -zcvf testfile1.tar.gz * [root@localhost tkedu]# tar -zcvf testfile2.tz * testfile2.tz: gzip compressed data,(和前面没有区别) 先解压,再看情况 解档+解压 tar -zxvf testfile2.tz | |
归档+bzip压缩 tar -jcvf test2.tar.bz2 * 解档+解压 tar -jxvf test2.tar.bz2 |
服务
which | 查询命令的脚本的时候 | [root@localhost bin]# which ls [root@localhost bin]# which tree | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
whereis | [root@localhost bin]# whereis ls [root@localhost bin]# whereis lftp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
locate | 关联了一个数据库,一周更新一次 更新一下数据库 | [root@localhost tmp]# touch 20200329 [root@localhost tmp]# locate 20200329 更新数据库,再查找 [root@localhost tmp]# updatedb [root@localhost /]# locate 20200329 [root@localhost /]# touch abc [root@localhost /]# updatedb [root@localhost /]# locate abc 注意点:不会去查找/tmp目录里面的信息 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| find | 文件、属性、时间、所有者... | [root@localhost /]# mkdir test [root@localhost /]# cd test/ [root@localhost test]# touch aa{1..5} [root@localhost test]# touch bb{1..5} [root@localhost test]# touch AA{1..5} [root@localhost test]# touch Aa [root@localhost test]# touch aax 246 dd if=/dev/zero of=file1 bs=1M count=1 247 dd if=/dev/zero of=file2 bs=1M count=2 248 dd if=/dev/zero of=file3 bs=1M count=3 249 dd if=/dev/zero of=file4 bs=1M count=4 250 dd if=/dev/zero of=file5 bs=1M count=5 [root@localhost test]# useradd user1 [root@localhost test]# useradd user2 [root@localhost test]# useradd user3 [root@localhost test]# chown user1:user2 aa1 aa2 [root@localhost test]# mkdir d{1..5}
对查找结果进行操作
|
计划任务
2020年3月29日
9:25
1 | at | 一次性的计划计划任务 | |
2 | | crontab | 周期性的计划任务 |
at
创建 | |
at now+5min | 五分钟后执行 |
at 2020-03-30 | 在2020-03-30的该时间点进行执行 |
at 7am 2020-03-30 | 指定具体的时间和日期,去执行任务 |
at 8am+10days | 十天之后去执行计划任务 |
at now+2weeks | 两周之后去执行计划任务 |
warning: commands will be executed using /bin/sh
at> echo "hello TengkeEDU" | 要执行的命令 |
at> <EOT> | ctrl+D |
job 1 at Sun Mar 29 14:50:00 2020
查看计划任务的信息 | atq 管理员可以看到 所有用户的计划任务 普通用户 只能看到自己的计划人任务 |
at -l | |
查看具体的,查看文件 | [root@localhost spool]# cd /var/spool/at/ 只有管理员有权限去查看 如果管理员/普通用户想查看自己的计划任务 具体信息 at -c 编号 |
删除特定编号的计划任务 | atrm 3 管理员 可以删除所有用户的计划任务 普通用户 只能删除自己的计划任务 |
不希望 普通用户去做计划任务 | [root@localhost at]# vim /etc/at.deny |
希望 普通用户去做计划任务 | (1)删除/etc/at.deny中的用户名字 (2)白名单/etc/at.allow(事先不存在),允许优先 vim /etc/at.allow 后续用户 做计划任务的时候,会去检查 是否在白名单中存在,不存在 不能创建 |
注意 | 去安装邮件服务--- yum list postfix |
crontab | 周期性的计划任务 |
创建计划任务 | crontab -e -u user1 |
删除(全删除) | crontab -r |
删除一条 | crontab -e |
vim /var/spool/cron/user1 |
分 | 时 | 天(几号) | 月份 | 周(星期) | 执行命令 | |
每天15:36打印hello | 36 | 15 | * | * | * | echo "hello" |
7:00,7:10,7:30 | 0,10,30 | 7 | * | * | * | echo "ok" |
7:00 ~ 7:15 每五分钟 | 0-15/5 | 7 | * | * | * | |
周一到周五 7:00 ~ 7:15 每五分钟 | 1,2,3,4,5 | |||||
1-5 | ||||||
偶数月执行 | 0 | 7 | * | 2,4,6,8,10,12 2-12/2 | 1-3,6 | |
1月到6月,1-10号或1-5 执行 7:00 | 0 | 7 | 1-10 | 1-6 | 1-5 |
分 & 时 & 月 & (天 | 周)
上网四要素 | IP地址、掩码、网关、DNS(考官设备的IP地址) |
查看IP地址 | ifconfig | RHEL6:eth1、RHEL7:eno16777736,RHEL8:ens160 |
(1)图形化界面、tui、nm-connection-editor & | ||
(2)命令行--nmcli的命令 [root@localhost ~]# nmcli connection show NAME(逻辑名字) UUID TYPE DEVICE(物理名字) ens160 2aca5006-5656-4002-a06d-f88c38b0af9d ethernet ens160 ens444 011f3a08-fdc9-4770-b7ba-afa2975a08ad ethernet ens224 查看详细信息 [root@localhost ~]# nmcli connection show ens444 [root@localhost ~]# nmcli connection show ens444 | grep ipv4 通过逻辑连接--断开连接 [root@localhost ~]# nmcli connection down ens444 通过逻辑连接--启动连接 [root@localhost ~]# nmcli connection up ens444 通过物理设备--断开连接 [root@localhost ~]# nmcli device disconnect ens224 通过物理设备--启动连接 [root@localhost ~]# nmcli device connect ens224 修改 [root@localhost ~]# nmcli connection modify id ens444 connection.id ens666 nmcli connection modify id 连接的名字 修改的属性 新名字 [root@localhost ~]# nmcli connection modify ens666 connection.autoconnect yes 删除 [root@localhost ~]# nmcli connection delete ens666 创建新的连接 [root@localhost ~]# 56 创建一个connection叫做 tkedu888的连接,模式是 以太网,网络可用时自动启动、给nmcli connection add con-name tkedu888 type ethernet autoconnect yes ifname ens2ens256网卡去使用 可以自动的获取,默认 获取IP地址的方式是DHCP 手动配置IP地址(先配置IP地址,再修改模式) 两下tab键 nmcli connection modify tkedu888 ipv4.addresses "192.168.127.88/24" nmcli connection modify tkedu888 ipv4.gateway "192.168.127.2" nmcli connection modify tkedu888 ipv4.dns "8.8.8.8" nmcli connection modify tkedu888 ipv4.method manual 能不能先修改 manual 再配置IP地址 一个网卡需要多个IP地址 nmcli connection modify tkedu888 ipv4.addresses "192.168.127.88/24" (只保留一个IP地址) nmcli connection modify tkedu888 +ipv4.addresses "192.168.127.88/24" 删除特定的IP地址 [root@localhost ~]# nmcli connection modify tkedu888 -ipv4.addresses "192.168.127.188/24" 重启网络服务 [root@localhost ~]# systemctl restart network 安装network-scripts-10.00.1-1.el8.x86_64.rpm软件 如果说对网络修改了 [root@localhost ~]# nmcli connection down tkedu888 [root@localhost ~]# nmcli connection up tkedu888 加载所有的连接 [root@localhost ~]# nmcli connection reload |
1.桥接模式:这种模式下,虚拟机和物理机连的是同一个网络,虚拟机和物理机是并列关系,地位是相当的。比如,你家有路由器,那么你的电脑和你的手机同时连接这个路由器提供的Wi-Fi,那么它们的关系就是这种模式。
2.NAT模式:这种模式下,物理机会充当一个“路由器”的角色,虚拟机要想上网,必须经过物理机,那物理机如果不能上网,虚拟机也就不能上网了。之所以说这种模式兼容性最好,是因为物理机的网络环境变化时,虚拟机的网络并不会有影响,比如,上班时你把物理机连接在公司的网络环境中,下班后又把物理机连接在你家的路由器上。你公司的网段有可能和你家的网段是不同的。桥接模式下,虚拟机和物理机一样,都要自动获取IP才可以上网,而做实验的时候,是需要把虚拟机设置为静态IP的,这样就导致虚拟机网络不稳定。而设置为NAT模式,虚拟机的网络并不需要依赖你公司的网络环境或者你家的网络环境。
3.仅主机模式:这种模式下,相当于拿一根网线直连了物理机和虚拟机。
--------------------- vim ifcfg-ens21
这边必须在管理员视图下进行操作。
Nmcli connection reload
归档(tar)和压缩(zip、gzip、bzip)
2020年3月29日
9:25
归档 | 打包 | 箱子+实际东西 | 整个文件是变大 |
压缩 | 体积减少 | 整个文件是变小 |
实验准备 | [root@localhost tmp]# rm -rf * [root@localhost tmp]# ls [root@localhost tmp]# mkdir tkedu [root@localhost tmp]# ls tkedu [root@localhost tmp]# ls -l tkedu/ total 0 [root@localhost tmp]# cp /etc/passwd /etc/shadow tkedu/ [root@localhost tmp]# ls -l tkedu/ total 8 -rw-r--r--. 1 root root 2487 Mar 29 10:58 passwd ----------. 1 root root 1308 Mar 29 10:58 shadow [root@localhost tmp]# ls -lh tkedu/ total 8.0K -rw-r--r--. 1 root root 2.5K Mar 29 10:58 passwd ----------. 1 root root 1.3K Mar 29 10:58 shadow | ||||||||||||||
归档 |
|
压缩 | gzip、bzip2、zip |
1 | 实验准备 | [root@localhost tkedu]# dd if=/dev/zero of=file bs=1M count=100 |
2 | gzip--gz | [root@localhost tkedu]# gzip file [root@localhost tkedu]# ll -h total 100K -rw-r--r--. 1 root root 100K Mar 29 11:17 file.gz 压缩之后,源文件自动删除,并且 生成 以gz结尾的文件 解压缩 -d [root@localhost tkedu]# gzip -d file.gz [root@localhost tkedu]# ll -h total 100M -rw-r--r--. 1 root root 100M Mar 29 11:17 file 解压之后,压缩文件自动删除 查看文件属性 [root@localhost tkedu]# file file.gz file.gz: gzip compressed data |
3 | bzip--bz2 | [root@localhost tkedu]# bzip2 file [root@localhost tkedu]# ll -h total 4.0K -rw-r--r--. 1 root root 113 Mar 29 11:17 file.bz2 [root@localhost tkedu]# bzip2 -d file.bz2 查看文件属性 [root@localhost tkedu]# file file.bz2 file.bz2: bzip2 compressed data, |
4 | zip | [root@localhost tkedu]# zip file.zip file 压缩之后,源文件不删除 [root@localhost tkedu]# unzip file.zip 解压的时候,压缩文件不删除 查看信息 [root@localhost tkedu]# file file.zip file.zip: Zip archive data |
归档和压缩的使用
归档+压缩 | tar -cvf 归档文件名字 归档文件 |
解档+解压缩 | tar -xvf 需要解档的文件 |
-z | gzip | [root@localhost tkedu]# tar --help | grep gzip tar -zcvf 归档文件名字 归档文件 tar -zxvf 需要解档的文件 |
-j | bzip | [root@localhost tkedu]# tar --help | grep bzip tar -jcvf 归档文件名字 归档文件 tar -jxvf 需要解档的文件 |
实验准备 | [root@localhost tkedu]# cp /etc/passwd /etc/shadow /etc/services . |
归档+gzip压缩 tar -zcvf testfile1.tar.gz * [root@localhost tkedu]# tar -zcvf testfile2.tz * testfile2.tz: gzip compressed data,(和前面没有区别) 先解压,再看情况 解档+解压 tar -zxvf testfile2.tz | |
归档+bzip压缩 tar -jcvf test2.tar.bz2 * 解档+解压 tar -jxvf test2.tar.bz2 |
服务
which | 查询命令的脚本的时候 | [root@localhost bin]# which ls [root@localhost bin]# which tree | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
whereis | [root@localhost bin]# whereis ls [root@localhost bin]# whereis lftp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
locate | 关联了一个数据库,一周更新一次 更新一下数据库 | [root@localhost tmp]# touch 20200329 [root@localhost tmp]# locate 20200329 更新数据库,再查找 [root@localhost tmp]# updatedb [root@localhost /]# locate 20200329 [root@localhost /]# touch abc [root@localhost /]# updatedb [root@localhost /]# locate abc 注意点:不会去查找/tmp目录里面的信息 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| find | 文件、属性、时间、所有者... | [root@localhost /]# mkdir test [root@localhost /]# cd test/ [root@localhost test]# touch aa{1..5} [root@localhost test]# touch bb{1..5} [root@localhost test]# touch AA{1..5} [root@localhost test]# touch Aa [root@localhost test]# touch aax 246 dd if=/dev/zero of=file1 bs=1M count=1 247 dd if=/dev/zero of=file2 bs=1M count=2 248 dd if=/dev/zero of=file3 bs=1M count=3 249 dd if=/dev/zero of=file4 bs=1M count=4 250 dd if=/dev/zero of=file5 bs=1M count=5 [root@localhost test]# useradd user1 [root@localhost test]# useradd user2 [root@localhost test]# useradd user3 [root@localhost test]# chown user1:user2 aa1 aa2 [root@localhost test]# mkdir d{1..5}
对查找结果进行操作
|