vtop takes more of a graphical approach to top, while concentrating more on simplicity. It displays CPU and Memory usage live charts, as well as a running process list. It runs on Node.js and can be easily installed with npm install -g vtop.
Features:
- Mouse clicks
- Themes
- Live chart (CPU, memory)
- Process list
gtop takes the graphical interface of vtop to another level. Just like vtop, it also displays a live chart of both CPU and memory, however gtop adds a network live chart to the list, and pie charts for both memory and swap, as well as storage usage.
gtop also runs on Node.js, and can easily be installed with npm install gtop -g.
Features:
- Live chart (CPU, memory/swap, network)
- Pie chart (memory, swap, disk usage)
- Process list
While s-tui is not a process monitoring utility, it displays great information about your process status. It’s python based and uses little resource. You can easily install it with sudo pip install s-tui.
Features:
- Processor info
- Live charts (CPU freq, utilization, temperature and power usage)
- Built-in CPU stress testing
Bash - Command Substitution, Subshell and Codeblock
Quick and simple differences between using $(..), (..) and {..;}.
$(command) or `command` - Command substitution (the output of a command replaces the command name) and is executed in a subshell. Please give preference to $(..) for better readability
( command ) - Command list is executed in a subshell
{ command ;} - Command list is executed in the current shell
Executing code
$ ( echo 123 )
123
$ $(echo 123) # this executes the output of the command
123: command not found
$ { echo 123 ;}
123
Fiding subshell level with built-in BASH_SUBSHELL variable
$ var=1
$ ( var=2 ) ; echo $var
1
$ $(var=2) ; echo $var
1
# Because we did not create a subshell,
# variable is available to original shell
$ { var=2 ;} ; echo $var
2
Other usages
Example 1:
Multiple commands and multiple lines. This can be used with (..) and {..}.
So you have a Bash script that you want to troubleshoot, but you want to send stdout to a file, and stderr to another. Here’s a solution.
For example, I like to use Bash’s color to display failure or success on checks, and echo’s removal of new lines (echo -e "Wait for it...\c ") to wait for checks. For example, the screenshot below shows a script that check each step and report back.
Errors are displayed in red, and success in green, and this same output is sent to the stdout and to a log file as well.
Now I want to get error messages in a separate log file, so I can go back to my original log and match the time where it failed, with additional verbose from Bash’s xtrace.
The solution is very simple… I can just add the lines below to the top of my script:
# Debugging
debug_log="${HOME}/bin/log/script.debug"
exec 2>>${debug_log}
set -x
The first line setups my debug log, the second redirects stderr to my debug log, and the third enables xtrace (same as bash -x [script]).
Note that doing this will disable any errors from being show in stdout.
Today I’m sharing instructions on how to record your teminal session, and not only share it, but also allow users to copy and paste text from the playback video.
The installation could not be easier. And to show how great this utility is, I’m showing the instructions using a “video” recorderd with “showterm”.
Now go ahead and try copying text from the video. Isn’t that great!?
Here’s a quick function that will display a prompt with timeout in a bash script:
_myCountdownFunction () {
echo -e "Hit \"Ctrl+c\" to quit or \"Enter\" to continue... \c"
cnt=5
while (( cnt >= 0 )) ; do
if (( cnt < 9 )) ; then
echo -e "\b\b${cnt}s\c"
elif (( cnt == 9 )) ; then
echo -e "\b\b\b ${cnt}s\c"
elif (( cnt <= 99 )) ; then
echo -e "\b\b\b\b ${cnt}s\c"
elif (( cnt < 999 )) ; then
echo -e "\b\b\b\b${cnt}s\c"
fi
read -t 1 my_reply
(( $? == 0 )) && exit 1
let cnt-=1
done
}
The user will see the following message on his terminal with the seconds counting down in place:
Hit "Ctrl+c" to quit or "Enter" to continue... 5s
At the end of the specified time in ‘cnt’, the script (where the function would be) will continue executing, and if the user hits “Ctrl+c” before that, it will exit (both script and function).
The function supports up to 999s (which should be enough).