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.
Similar Posts:
- [Solved] CURL Install Error: GnuTLS: The TLS connection was non-properly terminated. Unable to establish SSL connection.
- -Two solutions to bash: WGet: command not found
- What’s the difference between die() and exit() in PHP?
- -bash: wget: command not found [How to Solve]
- Redis service failed to start, prompt: redis server: command not found
- [Solved] Composer Install Error: PHP Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages:
- Make Command ERROR: “make:*** No targets specified and no makefile found.Stop.” [Three Method to Solve]
- Raspberry Pi3 Error: “Unable to determine hardware version. I see: Hardware : BCM2835”
- Centos7.4 appears Yum command not found [How to Solve]
- CentOS8 Install redis-6.0.6 make test:“ You need tcl 8.5 or newer in order to run the Redis test“