Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

#!/bin/bash

#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.

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
    
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. – paul 15 hours ago

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
share|improve this answer
    
I used chmod +x wget_test..could you elaborate on the cronjob being set to desired user? – paul 16 hours ago
    
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. – Pythonic 16 hours ago
    
Panic over..will try what you suggested – paul 16 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.