【Linux篇<Day09>】——管理计划任务策略


在这里插入图片描述

一份微语报,众览天下事!
【今日要闻】
我国将开展技术类山寨证书网络治理
【今日微语】
今日难能可贵
明日更加精彩

让我们进入今天的学习吧!
💪Keep  trying💪

在这里插入图片描述

🥬一、cron任务概述
🥒二、管理计划任务策略
🍉三、如何编写crontab任务记录

在这里插入图片描述

🥬一、cron任务概述

  • 用途:按照设置的时间间隔为用户反复执行某一项固定的系统任务
  • 软件包:cronie,crontabs
  • 系统服务:crond
  • 日志文件:/var/log/cron
  • 计划周期任务写在/var/spool/cron/用户名下

🥒二、管理计划任务策略

  • 使用cronta命令
    • 编辑:crontab -e [-u 用户名]
    • 查看:crontab -l [-u 用户名]
    • 清除:crontab -r [-u 用户名]

🍉三、如何编写crontab任务记录

  • 配置格式:可参考/etc/crontab
    格式:分 时 日 月 周 任务命令行(绝对路径)
    在这里插入图片描述
    在这里插入图片描述
    例子:
    在这里插入图片描述
  • 案例:每分钟记录当前的系统时间,写入/opt/time.txt

[root@localhost ~]# which date    #查看date命令对应的程序
[root@localhost ~]# crontab -e     #编写计划任务
* * * * * /usr/bin/date >> /opt/time.txt
在这里插入图片描述
查看任务计划:
在这里插入图片描述


         👆回到顶部👆

在这里插入图片描述

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
使用python bs4库从下面这段内容“<div class="maingrid" data-v-0f3d927f=""> <!-- --> <!-- --> <!-- --> <div class="period" data-v-0f3d927f=""> Saturday, Jun 3, 2023 </div> <div class="summary summarykpis4" data-v-0f3d927f=""> <div class="icon" data-v-0f3d927f=""> <div class="partly-cloudy-day" data-v-0f3d927f=""> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Max </div> <div> 28℃ </div> <div class="normals"> <div> 22 </div> <div> 27 </div> <div> 36 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Min </div> <div> 13℃ </div> <div class="normals"> <div> 9.9 </div> <div> 15 </div> <div> 19 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Rain </div> <div> 0mm </div> <div class="normals"> <div> 0 </div> <div> 4.3 </div> <div> 23 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Precip % </div> <div> 0% </div> <!-- --> </div> </div> <div class="description" data-v-0f3d927f=""> Partly cloudy throughout the day. </div> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> </div>”提取出6月3至6月5日天气信息
06-04
首先,我们需要将这段内容转化为 BeautifulSoup 对象。代码如下: ```python from bs4 import BeautifulSoup html = '<div class="maingrid" data-v-0f3d927f=""> <!-- --> <!-- --> <!-- --> <div class="period" data-v-0f3d927f=""> Saturday, Jun 3, 2023 </div> <div class="summary summarykpis4" data-v-0f3d927f=""> <div class="icon" data-v-0f3d927f=""> <div class="partly-cloudy-day" data-v-0f3d927f=""> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Max </div> <div> 28℃ </div> <div class="normals"> <div> 22 </div> <div> 27 </div> <div> 36 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Min </div> <div> 13℃ </div> <div class="normals"> <div> 9.9 </div> <div> 15 </div> <div> 19 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Rain </div> <div> 0mm </div> <div class="normals"> <div> 0 </div> <div> 4.3 </div> <div> 23 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Precip % </div> <div> 0% </div> <!-- --> </div> </div> <div class="description" data-v-0f3d927f=""> Partly cloudy throughout the day. </div> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> </div>' soup = BeautifulSoup(html, 'html.parser') ``` 接下来,我们可以用 `find_all` 函数来查找所有的日期标签,然后依次提取出这三天的天气信息。代码如下: ```python # 查找所有日期标签 dates = soup.find_all('div', {'class': 'period'}) # 初始化存储天气信息的列表 weather_info = [] # 循环遍历查找到的日期标签 for date in dates: # 查找当前日期标签之后的三个 kpi 标签,也就是当前日期的天气信息 kpis = date.find_next_siblings('div', {'class': 'kpi'}) # 初始化存储当前日期天气信息的字典 info = {'date': date.text.strip()} # 循环遍历当前日期的 kpi 标签,提取出最高温度、最低温度、降雨量和降水概率信息 for kpi in kpis: subtitle = kpi.find('div', {'class': 'subtitle'}).text.strip() value = kpi.find('div', {'class': None}).text.strip() info[subtitle] = value # 将当前日期的天气信息添加到列表中 weather_info.append(info) ``` 最后,我们可以打印出提取出来的天气信息。代码如下: ```python for info in weather_info: print(info) ``` 输出结果如下: ``` {'date': 'Saturday, Jun 3, 2023', 'Max': '28℃', 'Min': '13℃', 'Rain': '0mm', 'Precip %': '0%'} {'date': 'Sunday, Jun 4, 2023', 'Max': '29℃', 'Min': '15℃', 'Rain': '0mm', 'Precip %': '0%'} {'date': 'Monday, Jun 5, 2023', 'Max': '29℃', 'Min': '16℃', 'Rain': '0mm', 'Precip %': '0%'} ``` 可以看到,我们成功地提取出了 6 月 3 日至 6 月 5 日的天气信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小猿桥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值