想定期查询天气并提示我,很容易想到了创建定时任务然后给我自己发邮件,进而学习了linux如何发邮件,下面就开始吧。
mail命令看有没有安装,没有的话会提示安装mailutils,执行apt install mailutils安装,默认安装所有就好。which mailwhich mailxwhich sendmailwhich postfixvim /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 startecho today is a nice day! | mail -s today crab@163.comvim /home/popo/getweather.shcurl -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.weathervim /home/popo/send.shecho 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原文:https://www.cnblogs.com/pycrab/p/10199208.html