0

This question already has an answer here:

I want to download backup archives from one server to another. The server has a script that delivers the latest backup archive, the file has specific name for each date. I want wget to preserve that name.

When I run:

wget -q --content-disposition 'http://server.example.com/get/latest'

it does just what I want. I can also download the file with a browser.

However, when I put this in a shell script and try running it as cron job nothing happens. I don't see any errors in /var/log/syslog.

Here's the whole shell script:

#!/bin/sh
wget -q --content-disposition 'http://bkp.www1.linux.local/get/latest'

I also tried #!/bin/bash, same result.

What am I doing wrong?

marked as duplicate by Iain, HBruijn Aug 5 '16 at 6:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Already checked that basic stuff, I see that the cron job is executed in /var/log/syslog, but nothing gets downloaded with wget – johny332 Aug 4 '16 at 17:48
  • From the linked canonical question: "cron runs your command with cwd == $HOME Regardless of where the program you execute resides on the filesystem, the current working directory of the program when cron runs it will be the user's home directory. If you access files in your program, you'll need to take this into account if you use relative paths, or (preferably) just use fully-qualified paths everywhere, and save everyone a whole lot of confusion." in other words since you did not specify differently wget will download to your home directory. – HBruijn Aug 5 '16 at 6:12
0

You didn't gave details how you set up the cron job (user wide, system wide, ...) Are you sure the cron entry is properly formatted (like a field forgotten) ? an system cron entry should look like this

0 1 * * 0 root /usr/bin/my-command

I rephrase man 5 crontab

field          allowed values
-----          --------------
minute         0-59
hour           0-23
day of month   1-31
month          1-12 (or names, see below)
day of week    0-7 (0 or 7 is Sunday, or use names)
user           user of the system
command        the command to run (should be executable)

If you created a user cron entry, with crontab -e you should omit the user field.

Make sure the current working directory ( where the script is executed ) is writable to the script. Have a look to https://unix.stackexchange.com/questions/38951/what-is-the-working-directory-when-cron-executes-a-job

  • Created as crontab -e, here's the entry: 0 21 * * * /home/johny/big/bkp/vm/www1_partial/wget.sh – johny332 Aug 4 '16 at 17:45
  • What you said in the edited part lead me to the solution, my files were being downloaded into /home/johny, when I changed cron entry to cd /home/johny/big/bkp/vm/www1_partial && ./wget.sh it works as intended. Thanks – johny332 Aug 4 '16 at 20:24
  • @ryan-babchishin 's answer has good advises to set up a cron properly – Baptiste Mille-Mathias Aug 4 '16 at 20:55
1

Tell your script to write a log or do some of it's own debugging. Next time it runs, you'll have all of your answers. If it doesn't debug like it should, the next step is to blame cron.

I see you are not telling your script where to download to? Maybe you should? cd /some/path before wget?

My favourite

If your system can send email try adding a MAILTO variable to your crontab so any output (stdout/stderr) will go somewhere useful. I setup every server this way.

No more cron secrets!

0

Please check if your script is executable by adding permission as follow:

# chmod +x <your_script_name>

Next, check if the script can be executed under your current system user by:

# ./<your_script_name>

If everything is running fine, would you share your cron job setting for further check?

  • permissions are OK, the script is running when executed manually. – johny332 Aug 4 '16 at 17:43

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