Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to download images from a manufactures site using WGET. when I run the command from the shell it works fine. But when I run it from a file I am getting a placeholder file.

Here is the command:

wget --wait=2 --output-document=1000.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=8cb7afa6-73bf-4f9f-b251-38dc652779c9&size=large'

Here is what it looks like in a file:

wget --wait=5 --output-document=1101.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=4d41b2ff-90a4-40c1-9159-2780cd642244&size=large'
wget --wait=5 --output-document=1102.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=5e88f32e-48f2-40db-bdbd-53624448392d&size=large'
wget --wait=5 --output-document=1103.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=59292a17-ae6f-49df-a028-0a9f71686f80&size=large'

I can't figure out why it isn't working as a batch shell file.

share|improve this question
It's probably something small that's tripping it. Check this page for more info though - gnu.org/software/wget/manual/wget.html#Invoking – Adel Jul 12 '11 at 23:38
What does the placeholder contain? Are you invoking the script from the same shell where the direct call works? In particular, were the proxy settings the same? – Gilles Jul 13 '11 at 0:12
What is "Doesn't work"? What exactly is the output when it "Doesn't work"? How are you invoking it? Is this from a cron job? Are you passing it to a shell e.g. bash foo.sh? Are you executing by path e.g. ./foo.sh? – Sorpigal Jul 13 '11 at 11:45

migrated from stackoverflow.com Jul 13 '11 at 0:07

3 Answers

You know that you need to add an x (execute) flag on Unix to execute a shell script? Another common pitfall for DOS users is that for security reasons there is often no "." in the PATH Environment thus you need to run "./your-script" instead of just "your-script".

Concerning the she-bang mentioned in the other answer. At least on Linux /bin/sh is the default shell used if no she-bang is given inside the script. It is still good practice to always add one to all scripts.

share|improve this answer

I tested it here, and it worked fine. Do you have a she-bang line at the top? #!/path/to/shell

share|improve this answer
What do you mean? – coolbluelogo Jul 12 '11 at 23:58
At the top of your script, you need to write a she-bang - this is a line that tells your shell what program (in this case, sh, bash, ash, dash, csh, etc) you want to execute the shell. I'm not sure missing it would cause this sort of problem, but it's worth a shot. – AlexWebr Jul 13 '11 at 0:09
For bash it would be: #!/bin/bash – Johan Jul 13 '11 at 11:35
That depends on where bash is located. On my box, it's /usr/local/bin/bash ;) – AlexWebr Jul 13 '11 at 12:02
Try #!/usr/bin/env bash - most systems place env in /usr/bin, so it's pretty portable. The down side is that it's easy to intercept by adding a custom bash interpreter earlier in your PATH. – Sorpigal Jul 13 '11 at 14:38

Get the output from

which bash

and

which wget

then add the returned path to bash at the top of your script with a hash bang(#!). i.e if which bash return /bin/bash then use.

#!/bin/bash

Then add the returned path for wget. example

/usr/bin/wget --wait=5 --output-document=1101.jpg 'http://distributorcentral.com/resources/productimage

finally make sure the script you have created is executable chmod +x name-of-your-script

If its not working still try adding -x to your script to get some debugging info.

#!/bin/bash -x
share|improve this answer

Your Answer

 
discard

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