1、计划任务
1. 周期性计划任务
按照预先设置的时间周期(分钟、小时、天、月、周)重复执行用户执行的命令操作
服务名称crond
语法格式 :
Minutes Hours Day-of-Month Month Day-of-Week Command
分钟 小时 日 月 周 执行的命令,最好是命令的绝对路径
0-59 0-23 1-31 1-12 0-7
时间:
*:每*
*/5 每隔*次
,:不同的时间段
- : 表示范围
# 创建周期性计划任务
[root@bogon ~]# crontab -e
# 列出当前用户的计划任务
[root@bogon ~]# crontab -l
# 删除当前用户的计划任务
[root@bogon ~]# crontab -r
2. 实战
# 每分钟执行一次
* * * * * date > /root/date.txt
# 每天凌晨五点执行一次
0 5 * * * date > /root/date.txt
# 每月1日凌晨3点执行一次
0 3 1 * * date > /root/date.txt
# 每5分钟执行一次
*/5 * * * * date > /root/date.txt
# 每周六凌晨2点30分执行一次
30 2 * * 6 date > /root/date.txt
# 每月的5号,15号,25号,的凌晨2点执行一次
00 02 5,15,20 * * date > /root/date.txt
2、发送邮件
1.安装邮件服务mailx
[root@bogon ~]# yum install -y mailx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package mailx.x86_64 0:12.5-19.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================
Installing:
mailx x86_64 12.5-19.el7 base 245 k
Transaction Summary
==========================================================================================================================================
Install 1 Package
Total download size: 245 k
Installed size: 466 k
Downloading packages:
mailx-12.5-19.el7.x86_64.rpm | 245 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mailx-12.5-19.el7.x86_64 1/1
Verifying : mailx-12.5-19.el7.x86_64 1/1
Installed:
mailx.x86_64 0:12.5-19.el7
Complete!
2.1 发送邮件给系统用户
# 方式1
[root@bogon ~]# mail -s "邮件标题" 收件人
邮件内容
[root@bogon ~]# ctrl + d 结束发送
# 方式2
[root@bogon ~]# echo 内容 | mail -s "主题" 收件人
# 方式3
[root@bogon ~]# mail -s "主题" 收件人 < /etc/passwd
# 接受自己的邮件
[root@bogon ~]# mail
# 接受其他用户邮件[root用户权限]
[root@bogon ~]# mail -u 用户名
2.2 公网邮件发送
注意 qq、163、126等邮箱均为授权码登录,aliyun、gmail等邮箱均为密码登录
2.2.1 获取授权码
2.2.3 配置发送邮件信息
# 配置邮箱信息,在mail.rc文件中追加以下信息
[root@bogon ~]# vim /etc/mail.rc
# 你的邮箱地址
set from=chaosaigc@163.com
# 邮箱服务器地址, smtp.qq.com smtp.126.com
set smtp=smtp.163.com
# 你的邮箱地址
set smtp-auth-user=chaosaigc@163.com
# 邮箱密码或者是授权码
set smtp-auth-password=XXXXXXXXXXXXXX
set smtp-auth=login
set ssl-verify=ignore
2.2.4 发送邮件
[root@bogon ~]# cat /etc/passwd | mail -s "测试邮件" 1161733918@qq.com
2.2.5 发送邮件时携带附件
[root@bogon ~]# cat /etc/passwd | mail -s "测试邮件" -a "./a.jpg" 1161733918@qq.com
3、其他内容
1.创建&切换目录
# 创建用户
# useradd $username
# 判断用户是否存在
# id $username
# 切换用户
# su $username
# su - $username
# su 在切换用户的时候,切换用户前在哪一个目录,切换用户后还在哪一个目录
# su - 在切换用户时,切换用户并进入用户家目录
2.查看磁盘,内存使用情况
# 查看硬盘使用情况
# df -Th
# 查看内存使用情况
# free -m
# 测试连通性
# ping www.baidu.com
# 探测端口,明文传输数据
# telnet ip port
3.过滤
#过滤/搜索
#grep match_pattern file_name