How to execute HTTP get from un * x shell script on OS X system?(installing third-party software is not an option because it has to run on many different systems that I have no control over.).
For example, if I start mercurial server locally to execute Hg service:
... $ hg serve
Then, from Linux with the WGet command, I do a WGet:
... $ wget http://127.0.0.1:8000
--2010-12-31 22:18:25-- http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... 200 Script output follows
Length: unspecified [text/html]
Saving to: `index.html
On the terminal where I started the “Hg serve” command, I can see that HTTP get succeeded
127.0.0.1 - - [30/Dec/2010 22:18:17] "GET/HTTP/1.0" 200 -
So on Linux, one way to perform HTTP get from a shell script is to use WGet (if the command is installed of course).
Is there any other way to do the equivalent of a WGet?In particular, I’m looking for something to run on OS X installations.
#1st floor
brew install wget
Homebrew is the package manager of OSX, similar to yum, apt get, choco, emergency, etc. Note that you also need to install Xcode and command line tools. In fact, anyone who uses the command line in OSX will want to install these things.
If you can’t or don’t want to use homemade software, you can also:
Manually install WGet:
curl -# "http://ftp.gnu.org/gnu/wget/wget-1.17.1.tar.xz" -o "wget.tar.xz"
tar xf wget.tar.xz
cd wget-1.17.1
./configure --with-ssl=openssl -with-libssl-prefix=/usr/local/ssl && make -j8 && make install
Alternatively, use the bash alias:
function _wget() { curl "${1}" -o $(basename "${1}") ; };
alias wget='_wget'
#2nd floor
This is the WGet of Mac OS X equivalent to Linux.
For Linux, such as Ubuntu on an AWS instance, use:
wget http://example.com/textfile.txt
For local development on MAC, please use:
curl http://example.com/textfile.txt -o textfile.txt
The – O parameter is required on a Mac to output to a file instead of the screen. Specify a different destination name to rename the downloaded file.
Use uppercase – O and WGet to rename. Lowercase – O specifies the output file of the transfer log.
#3rd floor
1) on your Mac type
nano /usr/bin/wget
2) paste the following
#!/bin/bash
curl -L $1 -o $2
3) close and make it executable
chmod 777 /usr/bin/wget
That’s all.
#4th floor
Curl’s mode is almost equal to the default WGet.
curl -O <url&>
It’s like
wget <url&>
And, if you like, you can add it to. Bashrc:
alias wget='curl -O'
It’s not 100% compatible, but it works with the most common WGet usage (IMO)
#5th floor
You can build WGet on a Mac machine or install it directly using macports.
sudo port install wget
It can be like glamour, and you can update to the latest version as soon as possible. Ports are more stable than beer, but the recipe and number of ports are much less.
You can choose from https://www.macports.org/install.php
to install macports, you can download the . PKG
file and install it.