原文链接: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. vue-music 关于基础组件 (Tab组件)

      定义在项目的基础组类别的 tab组件中,定义一个tab切换数量的数组 和一个currentIndex 当前高亮索引 的props,当前高亮(active)的类等于currentIndex === ...

  2. centos定时备份数据库超简单示例

    #mkdir -p /home/db_backup#cd /home/db_backup #vim mysql_backup.shDATE=$(date +%Y%m%d_%H%M%S) /alidat ...

  3. 洛谷P2713 罗马游戏

    题目传送门 分析: 好吧,其实没什么好分析的,左偏树裸题. Code: #include<cstdio> #include<cstring> #include<cstdl ...

  4. hdu 5961 传递 (2016ccpc 合肥站 A题)

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  5. 【计算几何】【预处理】【枚举】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem K. Kiwi Trees

    发现由于角的度数和边的长度有限制,那俩圆如果放得下的话,必然是塞在两个角里. 于是预处理n个圆心的位置(注意要判断那个圆会不会和其他的边界相交),然后n^2枚举俩角即可. #include<cs ...

  6. 【Splay】bzoj3223 Tyvj 1729 文艺平衡树

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #i ...

  7. [NOIp2017提高组]宝藏

    #include<cstdio> #include<cctype> #include<algorithm> inline int getint() { regist ...

  8. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学

    C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...

  9. iOS中深拷贝、浅拷贝和retain的区别

    浅拷贝:浅拷贝是对object对象的指针拷贝,让指针指向同一块内存地址,“对象永远只有一个",浅拷贝使对象的引用计数器+1.代码如下: 可以看出不可变字符串的指针指向了同一地址,并没有重新开 ...

  10. 基于jquery,bootstrap数据验证插件bootstrapValidator

    bootstrap:能够增加兼容性的强大框架. 因为项目需要数据验证,看bootstrapValidator 还不错,就上手一直,完美兼容,话不多说. 需要引用css: bootstrap.min.c ...