标签:today mail 添加 查看 login 创建 命令 表示 cront
想定期查询天气并提示我,很容易想到了创建定时任务然后给我自己发邮件,进而学习了linux如何发邮件,下面就开始吧。
mail
命令看有没有安装,没有的话会提示安装mailutils,执行apt install mailutils
安装,默认安装所有就好。which mail
which mailx
which sendmail
which postfix
vim /etc/mail.rc
打开或者创建文件并填写以下内容:set from=crab@163.com set smtp=smtp.163.com set smtp-auth-user=crab@163.com set smtp-auth-password=****** set smtp-auth=login
/etc/init.d/postfix status
/etc/init.d/postfix start
echo today is a nice day! | mail -s today crab@163.com
vim /home/popo/getweather.sh
curl -H "Accept-Language:zh" wttr.in/paris > /home/popo/today.weather
,查询天气信息并写入文件chmod a+x /home/popo/getweather.sh
,修改可执行权限cd /home/popo
,尝试执行./getweather.sh
,查看天气cat today.weather
vim /home/popo/send.sh
echo Weather information has arrived.|mail -s "weather" crab@163.com < today.weather
发送天气邮件chmod a+x send.sh
,修改可执行权限./send.sh
,查看邮件是否收到crontab -l
,查看当前任务列表crontab -e
,编写任务0 12 * * * /bin/bash /home/popo/getweather.sh
和0 13 * * * /bin/bash /home/popo/send.sh
标签:today mail 添加 查看 login 创建 命令 表示 cront
原文地址:https://www.cnblogs.com/pycrab/p/10199208.html