Skip to content

Instantly share code, notes, and snippets.

@benwei
Last active November 14, 2019 08:24
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 benwei/3a3eb2c58e9b076b07120aeaba52ea40 to your computer and use it in GitHub Desktop.
Save benwei/3a3eb2c58e9b076b07120aeaba52ea40 to your computer and use it in GitHub Desktop.
Logging CPU load by top command per minute with BusyBox command environment
#!/bin/sh
## if you want to run toplog_per_minute.sh in background
## you have to use leading script to put it into backgroud without
## issue of "Stopped (tty output)" Error Message of script that
## stucked on busybox top command
## tested in BusyBox v1.20.2
##################################################################
/bin/sh /mnt/nand/toplog_per_minute.sh &
#!/bin/sh
TARGET_PREFIX=/mnt/mmc0/toplog
LOG_INTERVAL=60
run_top_once()
{
DATESTR="`date +'%Y%m%d-%H:%M:%S'`"
DATEONLY="${DATESTR:0:8}"
if [ "$DATEONLY" = "19700101" ]; then
return
fi
top_logname="${TARGET_PREFIX}${DATEONLY}.txt"
echo "D$DATESTR" >> $top_logname
top -b -n 1 >> $top_logname
## if you also want to log memory, please uncomment the next line
# free >> $top_logname
}
while [ 1 ] ; do
run_top_once ; sleep $LOG_INTERVAL;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment