sh 监视RSS提要以获取来自bash的更改

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 监视RSS提要以获取来自bash的更改相关的知识,希望对你有一定的参考价值。

#!/bin/bash
show_usage()
{
	echo "Usage: rss-diff -o original -f feed -t trim"
exit
}
MINARGS=2
case $1 in
	"-h"|"--help") show_usage; return 1; ;;
esac

ARGC=$#
if [[ $ARGC -lt $MINARGS ]] ; then
 echo "Too few arguments given (only command is optional)"
 show_usage
return 1;
fi
while getopts "o:f:t:" optname
    do
      case "$optname" in
        "o")
			 original=("$OPTARG")    
          ;;
		"f")
			 feed=("$OPTARG")          
	      ;;
        "t")
			 trim=($OPTARG)          
          ;;
        "?")
          echo "Unknown option $OPTARG"
          ;;
        ":")
          echo "No argument value for option $OPTARG"
          ;;
        *)
        # Should not occur
          echo "Unknown error while processing options"
			show_usage;return 1;
          ;;
      esac
    done
	if [ "$original" ]; then echo ""; else echo "original file is required";show_usage;return 1; fi
	if [ "$feed" ]; then echo ""; else echo "feed is required";show_usage;return 1; fi
	curl $feed > /tmp/feed.txt
	if [ "$trim" ];then contents=$(cat /tmp/feed.txt | tail -n +$trim);else contents=$(cat /tmp/feed.txt);fi
if diff $original <(echo "$contents") >/dev/null ; then
#On a Mac with terminal-notifier for Notification Center Support (https://github.com/alloy/terminal-notifier)
#/usr/bin/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "Feed Is Same" -message "$feed"
echo "Feed Is Same"
rm /tmp/feed.txt
exit
else
#On a Mac with terminal-notifier for Notification Center Support (https://github.com/alloy/terminal-notifier)
#/usr/bin/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "Feed Is Different!" -message "$feed" -open $feed
echo "Feed Is Different!"
if [ "$trim" ];then contents=$(cat /tmp/feed.txt | tail -n +$trim > $original);else contents=$(cat /tmp/feed.txt > $original);fi
rm /tmp/feed.txt
exit
fi

以上是关于sh 监视RSS提要以获取来自bash的更改的主要内容,如果未能解决你的问题,请参考以下文章

获取前缀:来自 XML RSS 提要的项目值

获取 RSS 提要时未定义

从 Feedburner RSS 提要中获取原始 XML 数据

sh watch是一个linux bash脚本,用于递归监视文件修改并在发生更改时执行bash命令

sh react是一个linux bash脚本,用于递归监视文件修改并在发生更改时执行bash命令

sh 暂时更改bash中的当前工作目录以运行命令 - 来自http://stackoverflow.com/questions/10382141/temporarily-change-