5 ms·
Has this happened to you? You're logged into a remote server and trying to read a config file or log file. The problem is its in a minified JSON format and look
by olooney 4y ago
Has this happened to you? You're logged into a remote server and trying to read a config file or log file. The problem is its in a minified JSON format and looks like a solid wall of noise when you try to use `less`. You reach for your go-to JSON swiss army knife `jq` but it's not installed! You don't have root access to install it via `apt-get` so you need a script you can run locally. Just copy the `jqjq` and `jqjq.jq` files to your local directory, and now you can access the full power of jq just by running `./jqjq`. Problem solved! And the best part is that the only dependency is `jq`, which should be installed pretty much everywhere.
- rpadovani 4y ago> And the best part is that the only dependency is `jq`, which should be installed pretty much everywhere. I am confused by this sentence. Wasn't the entire premise that js is NOT installed?
- foob 4y agoJokes aside, this is a actually a pretty common scenario for some people, and I wrote a tool called Exodus to solve it [1]. Exodus makes it trivial to relocate Linux binaries like jq from your local machine [1]. You can simply run exodus jq | ssh my-server locally, and then immediately have access to jq on the server. I personally find it very useful when working with servers or containers that have limited package repositories or where I don't have root access. [1] - https://github.com/intoli/exodus https://github.com/intoli/exodus
- efrecon 4y agoOoh. Thank you for Exodus! It is fantastic!
- andai 4y ago>Exodus handles bundling all of the binary's dependencies, compiling a statically linked wrapper for the executable that invokes the relocated linker directly, and installing the bundle in ~/.exodus/ on the remote machine. That's really neat.
- fwsgonzo 4y agoThat is very cool, and it's going to help me alot on old RHELs I think. Looks like it was actually very complicated to make!
- metadat 4y agoDiscussed 11 months ago: Exodus – relocation of Linux binaries–and all of their deps–without containers https://news.ycombinator.com/item?id=29446297 https://news.ycombinator.com/item?id=29446297 (307 points, 65 comments)
- kasbah 4y agoIn all seriousness Python's json.tool is a great option here. cat big.json | python3 -m json.tool or python3 -m json.tool big.json
- jwilk 4y agoThere's also json_pp(1), provided by Perl.
- ilyt 4y agoJoking aside ssh badly-managed-server cat file | jq . Problem solved ! I actually made a wrapper that just guesses (based on which parser returns error basically) type of serializing and then displays it nicely.
- eurasiantiger 4y agoThanks for this. The pattern is useful for much more and sure beats pushing ad-hoc 3rd-party-relinked binaries to production containers. Then again, why not scp the file to local? Bandwidth usage isn’t good for the environment.
- TheReveller 4y agoWhy stop at one file, is it possible to locally mount a remote folder over ssh?
- Too 4y agoYep, it's called sshfs, very easy to use.
- ilyt 4y agohere is function I use sshmount () { SSHFS_SERVER_DIR='/home/user' if [ "z$1" = "z" ] then echo "specify server [server_dir]" return fi SSHFS_SERVER=$1 if [ "z$2" != "z" ] then SSHFS_SERVER_DIR=$2 fi SSHFS_TARGET_DIR="/home/user/mnt/$SSHFS_SERVER" echo "Mounting $SSHFS_SERVER:$SSHFS_SERVER_DIR into $SSHFS_TARGET_DIR" mkdir -p $SSHFS_TARGET_DIR sshfs -o idmap=user -o allow_other -o kernel_cache $SSHFS_SERVER:$SSHFS_SERVER_DIR $SSHFS_TARGET_DIR && cd $SSHFS_TARGET_DIR } sshmount servername will mount server's home in directory /home/user/mnt/servername, second parameter changes the server dir to specified one
- cerved 4y agoYou can use cut, tr and sed https://stackoverflow.com/a/70614580/1507124 https://stackoverflow.com/a/70614580/1507124 it's not full pretty, rather just newline delimits arrays. Incidentally, it's much faster than jq. Probably wouldn't use it for anything serious
- deleted 4y ago[deleted]
- blackhaz 4y agoJust out of curiosity, why would anyone want to store a config file in a minified JSON format?
- yjftsjthsd-h 4y agoProbably computer generated and defaulted to compact output.
- yjftsjthsd-h 4y agoBravo; I got most of the way through before catching the joke:)