0

I have a program that contains two files: a python script and a shell script that downloads www.bing.com wallpaper and put it for my desktop background.

When I run this it works but it dosent work by my cron.

I have made a cronjob for that program but it dosen't work.

My cron entry is:

42 */4 * * * /home/ahmad/myBing/bingwallpaper.sh

my code:

#!/bin/bash

# Get download link and store it on downLink .
downLink=$(/home/ahmad/myBing/index.py)

# Making pic name .
picName=$(echo $downLink | cut -f7 -d"/")

# Set picture options
# Valid options are: none,wallpaper,centered,scaled,stretched,zoom,spanned
picOpts="zoom"

if [ $downLink != "net is off" ]
then
    mkdir -p $HOME/Pictures/BingDesktopImagePython/
    # Download the link by wget .
    wget -O $HOME/Pictures/BingDesktopImagePython/$picName "$downLink" &> /dev/null
    # Set the GNOME3 wallpaper
    gsettings set org.gnome.desktop.background picture-uri "file://$HOME/Pictures/BingDesktopImagePython/$picName"
    # Set the GNOME 3 wallpaper picture options
    gsettings set org.gnome.desktop.background picture-options $picOpts
else
    echo -e "Net is off :("
fi

# Exit the script
exit

and my python script:

#!/usr/bin/python
import re
import requests
import BeautifulSoup
import os

def getLink():
    if os.uname()[0] == "Linux":
        baseUrl = "http://www.bing.com"          
        imgUrl = "http://www.bing.com/HPImageArchive.aspx?format=xml&idx=1&n=1&mkt=en-US"
        try:
            html = requests.get(imgUrl)  # Get xml code .
        except:
            print ("net is off")    # it runs if net is off .
        else:
            soup = BeautifulSoup.BeautifulSoup(html.content)     
            link = soup.find('url',text = re.compile('(.jpg)$'))    #Get first <url> ... </url> string .
            downLink = baseUrl + link   # make download link .
            print (downLink)     
    else:
        print ("Your os should be Linux.")
        exit()
getLink()
Jacob Vlijm
  • 83,767
ahmad
  • 195
  • Sorry, probably a silly question, but... bingwallpaper.sh is used here, the file on your git page is called execIndex.sh. Presumably you've renamed execIndex.sh to bingwallpaper.sh? – John N Dec 06 '16 at 21:41
  • @JohnN ,oh yeah i ve renamed it. – ahmad Dec 06 '16 at 22:08

0 Answers0