DEV Community

Cover image for Monitor the performance of any command line program with this single command

Monitor the performance of any command line program with this single command

Agrim Prasad on July 07, 2018

This post was originally published on my blog, find original post here. I have been executing a lot of bash scripts and one-off processes on the l...
Collapse
 
ferricoxide profile image
Thomas H Jones II

Current style recommendations for shell scripts discourages the use of back-ticks. One would more typically do something like:

top -p $( gunzip -c LARGE_ARCHIVE_FILE.tgz > /dev/null & echo $! )

Using the $() method allows for nesting of commands without jumping through hoops to escape one command-execution nested within another)

Collapse
 
agrim profile image
Agrim Prasad

Thanks for the tip Thomas. I usually do use $() but didn't know that you don't need to escape nested command execution with it. Initially I used $() along with {} and it lead to errors on Mac (but not on Linux), so I switched to back-ticks which worked on both.

I'll update the article once I get near my computer and can test this out on both Mac and Linux, thanks again.

Collapse
 
ferricoxide profile image
Thomas H Jones II

Yeah... Being a long-time abuser of nested subshells, used to frustrate the hell out of me once I had to go more than about two subshells deep ...Sooner if one or more of those subshells required single- and/or double-quotes for some of their functionality.

Wasn't really until I started adding shellcheck to my TravisCi recipes that I habituated to the $() method. That tool also caused me to start moving off a few other habitual things that had been placed on the deprecation (but had worked for decades so were just "finger memory").

Collapse
 
joeleisner profile image
Joel Eisner

I'd definitely suggest checking out glances: It's an alternative to top/htop entirely written in Python, and it's a lot easier on the eyes/to parse IMO.

Collapse
 
ben profile image
Ben Halpern

Nice tip