Skip to content

Instantly share code, notes, and snippets.

@schmonz
Created April 2, 2015 16:06
Show Gist options
  • Save schmonz/b22c5bd06c9a379c9817 to your computer and use it in GitHub Desktop.
Save schmonz/b22c5bd06c9a379c9817 to your computer and use it in GitHub Desktop.
motd2rss
#!/bin/sh
#
# $ motd2rss < /etc/motd > motd.xml
#
# adapted a great deal from NetBSD's pkg-changes2rss
print_header()
{
cat <<EOF
<?xml version="1.0"?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
<rss version="0.91">
<channel>
<title>chicken-ac:/etc/motd</title>
<link>mailto:help@schmonz.com</link>
<description>Changes to chicken-ac</description>
<language>en-us</language>
<copyright>Schmonz Enterprises</copyright>
EOF
}
print_footer()
{
cat <<EOF
</channel>
</rss>
EOF
}
escape_entities()
{
echo "$1" | sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g'
}
print_item()
{
local title
title=`escape_entities "$1"`
cat <<EOF
<item>
<title>${title}</title>
</item>
EOF
}
main()
{
print_header
read line; read line; while read line && [ "${line}" ]; do
print_item "$line"
done
print_footer
}
main "$@"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment