JP Lew
JP Lew

Reputation: 4439

In UNIX, is it possible to "cat" a file over http?

Here is what I want to do:

cat https://raw.githubusercontent.com/jplew/SyncDB/master/syncdb

This gives a "No such file or directory" error, because cat, evidently, cannot grab a remote file over HTTP. Is there another way to accomplish this?

The Bigger Picture

I'm trying to write an auto-update function for my bash script. It needs to determine if the local version of the script is different from the latest public version. If there's a difference, it should download the new release.

I figured that I could test this using:

diff [local file] [remote file]
diff syncdb https://raw.githubusercontent.com/jplew/SyncDB/master/syncdb

But this gives the same problem as above: "No such file or directory". So my second idea was to try this:

cat https://raw.githubusercontent.com/jplew/SyncDB/master/syncdb | diff - syncdb

Because this script is used by the public, they don't have SSH access to the public github repo. Secondly, I prefer not to use git diff to compare files, because this requires that they have git installed, messes up the proper file location/structure, and also requires that they've cloned my repo, which I prefer to avoid as a requirement.

I know I could download the raw remote file using curl or wget, then diff them, but this defeats the whole purpose of checking to see if there are any changes before downloading.

Thanks for reading!

Upvotes: 0

Views: 1651

Answers (2)

user1848722
user1848722

Reputation: 21

I highly recommend using wget and then use cat to display the file's contents.

wget https://raw.githubusercontent.com/jplew/SyncDB/master/syncdb && cat syncdb

Upvotes: 2

atupal
atupal

Reputation: 17210

Maybe curl will help you

curl  https://raw.githubusercontent.com/jplew/SyncDB/master/syncdb | diff - syncdb

Upvotes: 6

Related Questions