使用*nix给你的Kindle推送卫报

正好在读卫报,写个给 Kindle 推送的小脚本,适用于所有带cPanel的空间,使用Cron jobs来自动定时推送,或者你自己的电脑、VPS之类的都行。

脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
 
#this part will generate the file name, such as: gdn-2012-03-05.mobi
prefix='gdn-';
date=`date '+%Y-%m-%d'`;
file=$prefix$date.mobi;
 
#here is the push addres of your kindle. for multiple push please separate with ,
emailto='这里填写你的kindle推送地址';
 
#subject of the email that goes out
emailsubject='Kindle Push for ';
 
#body of the email can be defined here
emailbody='Reach the attachemnt for push of the day. ';
 
wget -q http://mythic-beasts.com/~mark/random/guardian-for-kindle/$file
echo $emailbody | mutt -s "$emailsubject$date" -a $file "$emailto";
rm $file


将脚本修改好后保存为*.sh,并赋予可执行权限:

chmod +x *.sh

然后到cPanel的cron jobs增加一条:

~/*.sh >/dev/null 2>&1

(如果你将脚本放到用户根目录下的话)

这份期刊大概会在每天伦敦时间5点左右生成,就是北京时间下午1点,cronjob的时间请根据服务器所在位置调整。服务器时间可使用date命令查看。

还有,记得把发信地址加入推送的信任列表里面哦~
P.S. 如果无法确定发信地址,请把脚本里面的推送地址改为自己的邮箱并手动运行一次即可见到。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.