前面一篇文章也是下载VOA,但是由于iphone cron不能在休眠时用而需要配合电脑才能下载。
后来研究了一下iphone的启动步骤,发现可以在/System/Library/LaunchDaemons添加定时job.所以整个iphone自动下载当天VOA设置如下:
1.脚本: /var/mobile/sh/getVoa.sh
cd /var/mobile/voa/today=`date +%m-%d|sed 's/^0\+//'|sed 's/-0/-/'`mkdir $todaycd $today`wget -O voa.html http://www.51voa.com/`domain="http://www.51voa.com"urlList=`sed 's/"/\n/g' /var/mobile/voa/$today/voa.html | grep -C 4 $today |grep "\(VOA_Special_English\)\|\(VOA_Standard_English/\)\|\(Voa_English_Learning\)/.*html"`echo $urlListfor i in $urlListdo`wget -O temp.html ${domain}${i}`mp3=`sed 's/"/\n/g' /var/mobile/voa/$today/temp.html | grep "/path.asp?url"`echo "------------------$mp3"if [ -n "$mp3" ]; thenecho $mp3`wget $domain$mp3 --content-disposition`filrc=`sed 's/\("\|><\|href=\)/\n/g' /var/mobile/voa/$today/temp.html| grep \.lrc|awk '{print $1}'|sed 's/img//g'`echo "------------------$lrc"if [ -n "$lrc" ]; thenecho $lrc`wget $domain$lrc --content-disposition`fidonerm *html
2./System/Library/LaunchDaemons添加文件 com.downvoa.plist
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>Label</key> <string>com.downvoa</string> <key>ProgramArguments</key> <array> <string>/var/mobile/sh/getvoa.sh</string> </array> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>22</integer> <key>Minute</key> <integer>55</integer> </dict> <key>UserName</key> <string>root</string></dict></plist>
3.加载此文件:launchctl load com.downvoa.plist
那么每晚的22:55分iphone4就会去下载当天的voa,保存在/var/mobile/sh/{月-日} 的文件夹下。