Skip to content

Instantly share code, notes, and snippets.

@chakib-belgaid
Created July 12, 2021 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakib-belgaid/6a45f723644c4f8701cabf2daa16f06c to your computer and use it in GitHub Desktop.
Save chakib-belgaid/6a45f723644c4f8701cabf2daa16f06c to your computer and use it in GitHub Desktop.
#! /bin/sh
# a script that let you record the result of htop each $StepDuration in $ReportFile
##### HOW TO USE
## instead of CMD run recordtop.sh CMD
while getopts "d:o:" o; do
case "${o}" in
d)
StepDuration=${OPTARG}
;;
o)
ReportFile=${OPTARG}
;;
esac
done
shift $((OPTIND - 1))
StepDuration=${StepDuration:-0.5}
ReportFile=${ReportFile:-$1'.report.htop'}
nohup $@ &
pid=$!
echo $pid
top -b -H -p $pid -d $StepDuration >$ReportFile &
wait $pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment