Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

opusthe2nd

macrumors 6502
Original poster
This is it:

#! /bin/bash
cd /Users/opus/Documents/escan/
rm mwav.*
wget http://update3.mwti.net/download/tools/mwav.exe


I can run it all manually, but when it runs with cron I get:

/Users/opus/Documents/escan/mwave.sh: line 4: wget: command not found.

I've tried it with full path and get same error. /usr/sbin/wget

What am I missing here?
 
You have to download and compile wget for os x. I had the same problem.

- James

Edit:
You can try this, but it is old:
http://www.versiontracker.com/dyn/moreinfo/macosx/13923&vid=59439

or


Get the source from ftp://ftp.gnu.org/pub/gnu/wget/wget-1.9.tar.gz
Unpack the tarball: tar xzf wget-1.9.tar.gz
This creates a folder named wget-1.9. Change the working folder to it: cd wget-1.9/
Configure the build: ./configure
Build: make
Install: sudo make install
The wget binary should now be in your /usr/local/bin folder.
 
Ha...well of course I have already done that. Like I said, if I run the command manually it works.

This is Leopard, I forgot to mention. There is no /usr/local/bin.
 
When you run scripts from cron they generally don't have a PATH as it doesn't get the environment initialized in the same way as when you're in a shell.

Type 'which wget' to get the path to wget. Then put the full path in your script, it should then work fine.
 
I have and it doesnt. If I put it in manually it will, but the script, when run with cron, spits out that error. wget not found. If I run the script manually, it works fine. I am doing this all as user and not sudo. I shouldnt have to put it in the su crontab....I dont think.
 
have you tried curl? it's included on all macs and it should do the job..
It would look something like this:

Code:
! /bin/bash
cd /Users/opus/Documents/escan/
rm mwav.*
curl -L http://update3.mwti.net/download/tools/mwav.exe >> /dev/null

I added the /dev/null so you dont get mails with the outputs..
 
When I do curl -L http://update3.mwti.net/download/tools/mwav.exe all I get is rapid scrolling text and beep, beep, beep, beep. Whats wrong with wget? I'm too old to learn anything new. 🙂

I'm sorry, I'm stupid.. it should be
-O not -L.. so

Code:
curl -O http://update3.mwti.net/download/tools/mwav.exe

the -O means to write the output of what ever you download to a local file name that is the same as the remote file name..

And there's nothing wrong with wget. In fact, I prefer wget... but, if you had too many problems with wget, curl is built in.... 😎




edit: you could use the -s option to make it silent too..
 
I'd second the curl recommendation. I wasn't able to reproduce your original error.. I received the 'wget: command not found' error like you did until I provided the full path.. after that the script worked fine. Perhaps a typo?

If you still can't get it to work after trying curl, please post a copy of your script that contains the full path along with the output from:

which wget

When you say it works if you run it manually, do you mean if you run the script from the command line, or if you run each command one at a time from the command line?

You could also try explicitly defining your PATH at the top of your script. Type the following to grab the current PATH:

env | grep ^PATH

which should give you something like:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

and add the PATH= line as line 2 of your script.

The default path that is used in the cron environment is very minimal:

PATH=/usr/bin:/bin
 
Maybe when it runs as a cron job, it doesn't have rights to access wget.

Determine what user the cron jon runs as and make sure that user can execute wget.
 
I would think cron is running as user, seeing thats how I created it. It seems to be working now with the PATH changed as above.

I'm a FBSD guy that has moved over to OS X, somethings seem to be different.
 
It seems to be working now with the PATH changed as above.

Cool. This means the wget command is in one of those additional directories, and perhaps not where you originally thought it was.. you're good to go, but if you want to bottom out on this:

GNU Wget 1.9+cvs-dev

When I said 'which wget', I meant run the 'which wget' command and tell me what it comes back with. Should be something like /usr/local/bin/wget. Then do a 'file /usr/local/bin/wget' to make sure it's an executable and not yet another script that may have issues itself.
 
Wget did not work after all. "which wget" = /usr/sbin/wget. Which is what I have been using. I tried it with curl and that worked.

My script runs, yet it cant find wget....even though the path is there. Still odd. It should run as user, as I have run it as user.

Its got to be solely a cron issue. I have run the script manually, I have run each line in the script manually, etc. I could sudo crontab -e but I shouldnt have to.
 
Good, so it's not a broken script itself, at least.

within cron, your path is preset to /usr/bin:/bin

Try this at the command line to emulate that environment:

your-prompt$ PATH=/usr/bin:/bin yourscriptname

This will force your script to run with that PATH, and should give the same error it does in cron. Also, please post your entire script as it looks when it fails using the above syntax.
 
I ran:

PATH=/usr/bin:/bin /Users/opus/Documents/escan/mwave.sh

and it worked.

Maybe I can put wget in /usr/bin?
 
That would fix it, too.

Just to satisfy my curiosity, could you post the script again as it is right now?
 
sounds like you've got it working. Still a mystery to me, but oh well. Only other thing I can think of is an alias to wget or something in your .bashrc that works for your interactive shell but not for your non-interactive shell in cron.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.