原文链接: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

  

[转]bing壁纸天天换 初识shell魅力的更多相关文章

  1. 【壁纸自动换】自动下载、更换壁纸(Bing壁纸)--XinBSBingWallPaper[2.7更新]

    XinBSBingWallPaper主要功能: 1.支持自动下载Bing壁纸.Netbian壁纸.美国国家地理杂志图片. 2.自动搜索.下载多国Bing首页壁纸. 3.支持定时自动更换桌面壁纸. 4. ...

  2. 初识Shell与Shell脚本

    初识Shell Shell 是一个用 C 语言编写的程序,Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内 ...

  3. Linux基础入门(一)初识Shell

    Linux基础入门(一)初识Shell shell是什么 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言. Shell ...

  4. 我们一起来学Shell - 初识shell

    文章目录 Shell 的分类 `bash` `csh` `ksh` `tcsh` `sh` `nologin` `zsh` Shell 能做什么 bash 环境变量文件 `/etc/profile` ...

  5. Ubuntu 设定壁纸自动切换的shell脚本

    升级到Ubuntu14.04后,感觉bug的确比12.04少多了.顶部任务栏支持半透明效果,所以整个桌面也看上去漂亮了很多.这样的桌面也是值得瞎捣鼓一下的,想到换壁纸,但是没找到设定动态更换壁纸的选项 ...

  6. window10自动更换bing壁纸

    问题描述: bing的每日推荐的首页壁纸很不错,想当做系统壁纸! https://cn.bing.com/ 问题解决: 在window-store商店搜索  “Dynamic Theme”,安装即可! ...

  7. 自动同步bing壁纸

    在百度搜东西,经常出来一大坨广告:要么就是复制粘贴文章.完全没有创新,搜索越来越困难.偶尔用一下bing还挺好用. bing的壁纸是真心好看,每天不重样.决定写个脚本同步一下它的壁纸. 一.以我的Wi ...

  8. 1.初识Shell脚本语言

    PS:在做Linux下STM8固件升级项目中,需要让CPU通过I2C总线给STM8传输数据,刚开始一个一个的敲,很浪费时间,用shell脚本大大提高了数据传输效率,它是用户与内核进行交互操作的一种接口 ...

  9. bing壁纸xml地址

    http://www.bing.com/gallery/?src=livesino# http://www.bing.com/HPImageArchive.aspx?format=xml&id ...

随机推荐

  1. textarea 内容不可编辑 自是适应高度 只读相关属性配置

    不可编辑: <textarea disabled="disabled"></textarea> 如果仅仅用于禁止输入(只读,但有用),使用readonly属 ...

  2. 如何访问mvc 默认的错误页

    在ActionResult 中: public ActionResult Error() { return View("~/Views/Shared/Error.cshtml"); ...

  3. Django常用内置过滤器

    1.add 此过滤器将首先尝试将两个值强制为整数.如果失败,它会尝试将值一起添加.这将工作在一些数据类型(字符串,列表等)和失败在其他人.如果失败,结果将是一个空字符串. {{ value | add ...

  4. 用Pandas获取商品期货价格并可视化

     用Pandas获取商品期货价格并可视化 摘  要 1.用pandas从excel中读取数据: 2.用pandas进行数据清洗.整理: 3.用bokeh进行简单的可视化. 1.数据读取 本文主要是将获 ...

  5. NGUI 简单的背包系统

    1.首先在场景中创建格子,用来存放物体的 2.为每一个格子设置标签为Item,建议只做一个格子,然后创建预制体就可以了,然后为每一个格子附加Box Collider组件,要用于检测嘛, 3.接下来就是 ...

  6. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  7. 【Java】【高精度】【递推】UVA - 11375 - Matches

    d[i+c[j]]+=d[i](c[j]是拼成j所需的火柴数) d[0]=1: 别忘了不能有前导零,所以当i为零时,不要尝试去拼成零.反而应该在n>=6时,最后给答案加1(单独拼出0). imp ...

  8. 【数论】【扩展欧几里得】hdu3579 Hello Kiki

    解一元线性同余方程组(模数不互质) 结合看这俩blog讲得不错 http://46aae4d1e2371e4aa769798941cef698.devproxy.yunshipei.com/qq_27 ...

  9. python基础--接口与归一化设计、封装、异常、网络编程

    1 接口与归一化设计 1.1 归一化概念: 归一化的好处: 1.归一化让使用者无需关心对象的类是什么,只需要知道这些对象都具备某些功能就可以了,这极大降低了使用者的使用难度. 2.归一化使得高层的外部 ...

  10. 浙南联合训练赛 H - The number of positions

    Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say ...