In the process of learning/understanding Linux (difficult but enjoying it). I have written a very short shell script that uses wget to pull an index.html file from a website.


#Script to wget website mywebsite and put it in /home/pi/bin

index=$(wget www.mywebsite.com)

And this works when i enter the command wget_test into command line. It outputs a .html file into /home/pi/bin.

I have started trying to do this via cron so i can do it at a specific time. I entered the following by using crontab -e

23 13 * * *   /home/pi/bin/wget_test

In this example I wanted the script to run at 13.23 and to output a .html file to /home/pi/bin but nothing is happening.


2 Answers 2


This line index=$(wget www.mywebsite.com) will set the variable $index to nothing. This is because (by default) wget doesn't write anything to stdout so there's nothing to put into the variable.

What wget does do is to write a file to the current directory. Cron jobs run from your $HOME directory, so if you want to write a file to your $HOME/bin directory you need to do one of two things

  1. Write wget -O bin/index.html www.mywebsite.com
  2. Write cd bin; wget www.mywebsite.com

Incidentally, one's ~/bin directory is usually where personal scripts and programs would be stored, so it might be better to think of somewhere else to write a file regularly retrieved from a website.

  • Thanks Roaima, I have it working now, the files were being sent to $Home Directory but with cd bin; I was able to get them where they needed to be.
    – heroZero
    Mar 13, 2017 at 14:48

Make sure your bash script has permissions to be executable and make sure the cronjob is set on the desired user.

What I think is happening though is that the command in your script just needs to be:

wget www.mywebsite.com/index.html
  • I used chmod +x wget_test..could you elaborate on the cronjob being set to desired user?
    – heroZero
    Mar 13, 2017 at 13:43
  • See my edit and when I said cronjob being set to the desired user I mean every user has their own cron jobs. So if you want the pi user to run this then make sure this job is in the pi user's crontab. Logged in as the pi user you can use crontab -e to verify this.
    – ProdIssue
    Mar 13, 2017 at 13:46
  • Panic over..will try what you suggested
    – heroZero
    Mar 13, 2017 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .