我希望使用个人RSS Feed进行系统报告,所以我想知道是否有可能创建一个脚本,将其$1发送到RSS feed,ala self_test_command > rss_report.sh。我目前也没有设置RSS提要,那么设置从Linux机器上运行的RSS提要最简单的方法是什么?
发布于 2012-10-11 04:21:13
我有一个合适的解决方案,在command line中。在后台使用Perl Template::Toolkit模块(现在不需要学习Perl ):
首先安装perl-template-toolkit包,然后创建模板文件rss.tpl:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>[% title %]</title>
<description>[% desc %]</description>
</channel>
<!-- rest of the RSS -->
</rss>然后运行以下命令:
tpage --define title=foobar --define desc=description --interpolate rss.tpl输出为:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>foobar</title>
<description>description</description>
</channel>
<!-- rest of the RSS -->
</rss>您将找到用于修改here的完整模板
发布于 2013-01-18 18:53:27
还有另一种使用xmlstarlet的解决方案
创建初始rss文件feed.xml:
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>My RSS Feed</title>
<description>This is my RSS Feed</description>
</channel>
</rss>创建一个使用xmlstarlet添加项目的shell脚本:
#!/bin/sh
TITLE="My RSS entry"
LINK="http://example.com/entry4711"
DATE="`date`"
DESC="Good news"
GUID="http://example.com/entry4711"
xmlstarlet ed -L -a "//channel" -t elem -n item -v "" \
-s "//item[1]" -t elem -n title -v "$TITLE" \
-s "//item[1]" -t elem -n link -v "$LINK" \
-s "//item[1]" -t elem -n pubDate -v "$DATE" \
-s "//item[1]" -t elem -n description -v "$DESC" \
-s "//item[1]" -t elem -n guid -v "$GUID" \
-d "//item[position()>10]" feed.xml ; 当然,为了有一个通用的解决方案,人们更喜欢从命令行传递参数。
-d命令确保提要不会增长到inifinet,而是最多包含10个项目。
https://stackoverflow.com/questions/12827343
复制相似问题