Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Jokes 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


>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.


Discussed 11 months ago:

Exodus – relocation of Linux binaries–and all of their deps–without containers

https://news.ycombinator.com/item?id=29446297

(307 points, 65 comments)


That 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!


Ooh. Thank you for Exodus! It is fantastic!


Joking 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.


Thanks 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.


Why stop at one file, is it possible to locally mount a remote folder over ssh?


here 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


Yep, it's called sshfs, very easy to use.


In 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


There's also json_pp(1), provided by Perl.


> 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?


I believe that that was the joke


You understood the joke, you just didn't find it funny.


You can use cut, tr and sed

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


Bravo; I got most of the way through before catching the joke:)


Just out of curiosity, why would anyone want to store a config file in a minified JSON format?


Probably computer generated and defaulted to compact output.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: