探索 Linux 趣味脚本与命令指南
1. 每日励志名言脚本
在 Linux 系统中,我们可以创建一个脚本来获取每日励志名言。以下是脚本代码:
check_url=$(wget -nv --spider $quote_url 2>&1)
#
if [[ $check_url == *error404* ]]
then
echo "Bad web address"
echo "$quote_url invalid"
echo "Exiting script..."
exit
fi
#
# Download Web Site's Information
#
wget -o /tmp/quote.log -O /tmp/quote.html $quote_url
#
# Extract the Desired Data
#
sed 's/<[^>]*//g' /tmp/quote.html |
grep "$(date +%B' '%-d,' '%Y)" -A2 |
sed 's/>//g' |
sed '/ /{n ; d}' |
gawk 'BEGIN{FS=" "} {print $1}' |
tee /tmp/daily_quote.txt > /dev/null
#
exit
这个脚本的执行流程如下:
1. 检查网址是否有效,如果返回 404 错误,则输出错误信息并退出脚本。
2. 使用 wget 下载网页信息到 /tmp/quot
超级会员免费看
订阅专栏 解锁全文
176

被折叠的 条评论
为什么被折叠?



