原文链接:http://www.cnblogs.com/atskyline/p/3679522.html

  原文的程序跑在window上,curl的使用不太一样,想要获取的图片也不太一样。修改后的代码如下:

#!/bin/bash

# export DBUS_SESSION_BUS_ADDRESS environment variable useful when the script is set as a cron job
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-) # $bing is needed to form the fully qualified URL for
# the Bing pic of the day
bing="cn.bing.com" # $xmlURL is needed to get the xml data from which
# the relative URL for the Bing pic of the day is extracted
#
# The mkt parameter determines which Bing market you would like to
# obtain your images from.
# Valid values are: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA.
#
# The idx parameter determines where to start from. 0 is the current day,
# 1 the previous day, etc.
xmlURL="-d 'format=xml&idx=0&n=1&mkt=zh-CN' --get http://cn.bing.com/HPImageArchive.aspx" # $saveDir is used to set the location where Bing pics of the day
# are stored. $HOME holds the path of the current user's home directory
saveDir="$HOME/Pictures/Bing/" # Create saveDir if it does not already exist
mkdir -p $saveDir # Set picture options
# Valid options are: none,wallpaper,centered,scaled,stretched,zoom,spanned
picOpts="zoom" # The desired Bing picture resolution to download
# Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200"
desiredPicRes="_1920x1200" # The file extension for the Bing pic
picExt=".jpg" # Extract the relative URL of the Bing pic of the day from
# the XML data retrieved from xmlURL, form the fully qualified
# URL for the pic of the day, and store it in $picURL # Form the URL for the desired pic resolution
desiredPicURL=$bing$(echo $(curl $xmlURL) | grep -oP "<urlBase>(.*)</urlBase>" | cut -d ">" -f 2 | cut -d "<" -f 1)$desiredPicRes$picExt # Form the URL for the default pic resolution
defaultPicURL=$bing$(echo $(curl $xmlURL) | grep -oP "<url>(.*)</url>" | cut -d ">" -f 2 | cut -d "<" -f 1) # $picName contains the filename of the Bing pic of the day # Attempt to download the desired image resolution. If it doesn't
# exist then download the default image resolution
if wget --quiet --spider "$desiredPicURL"
then # Set picName to the desired picName
picName=${desiredPicURL##*/}
# Download the Bing pic of the day at desired resolution
curl -s -o $saveDir$picName $desiredPicURL
else
# Set picName to the default picName
picName=${defaultPicURL##*/}
# Download the Bing pic of the day at default resolution
curl -s -o $saveDir$picName $defaultPicURL
fi # Set the GNOME3 wallpaper
gsettings set org.gnome.desktop.background picture-uri "file://$saveDir$picName" # Set the GNOME 3 wallpaper picture options
gsettings set org.gnome.desktop.background picture-options $picOpts # Remove pictures older than 30 days
#find $saveDir -atime 30 -delete # Exit the script
exit

  然后用crontab,做成每日任务,就可以天天换bing壁纸了。crontab代码如下:

# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# m h dom mon dow command
15 1 * * * /home/kuizhi/program/bingWallPaper.sh

  

最新文章

  1. speex进行音频去噪
  2. 12个Linux进程管理命令介绍
  3. python 基础理解...
  4. Stacked injection--堆叠注入--堆查询注入
  5. Android中ProgressDialog的简单示例
  6. 返回canceled 代码 的原因
  7. 移动设备、手机浏览器Javascript滑动事件代码
  8. Android LinearLayout中weight属性的意义与使用方式
  9. String的format方法
  10. 编写一个飞行棋项目(C#)遇到几个问题:
  11. 读书笔记之《深入理解Java虚拟机》不完全学习总结
  12. 在EF中正确的使用事务
  13. Http系列目录
  14. java.util.concurrent.TimeoutException: Idle timeout expired: 300000/300000 ms
  15. python-web自动化-元素操作:windows窗口切换 / alert切换 / iframe切换
  16. vue 自动化部署 jenkins 篇
  17. 在Java应用中通过SparkLauncher启动Spark任务
  18. week5 0.2 client
  19. Nagios配置文件nagios.cfg详解
  20. Oracle之SYSDBA的使用

热门文章

  1. SPOJ11469 Subset(折半枚举)
  2. Gym - 101620I Intrinsic Interval
  3. 【分块】【bitset】hdu6085 Rikka with Candies
  4. 【模拟+递归+位运算】POJ1753-Flip Game
  5. Perl中的数组&amp;哈希应用
  6. nginx和php-fpm的用户权限
  7. idea小问题解决方法系列
  8. stream_get_meta_data(打开的文件句柄) 拿到任何网站服务器名字,从封装协议文件指针中取得报头/元数据
  9. 判断隐式Intent是否有响应
  10. 既然有文件后缀名,为何还需要MIME类型?