#!/bin/bash
###
### Sample background worker script
### for linuxquestions.org written
### by Florian Harbich (user doc.nice)
###
### Free for use or modification, even if
### useless in this variant...
###
# to terminate the script
# run "touch /var/run/backgroundworker.ctl"
# as root.
TERMINATORFILE=/var/run/backgroundworker.ctl
GOON=1
# the original while [ $GOON ] didn't work
# for me so changed to [ $GOON -ne 0 ]
while [ $GOON -ne 0 ]; do
[ -f "$TERMINATORFILE" ] && GOON=0
# echo $GOON
# do your repeated stuff here
LOG=/home/myuser/free.log
# date time formatted as
# YYYYMMDD HH:MM:SS
DT=`date +"%Y%m%d %H:%M:%S"`
# this gets the _used_ memory
FR=`free -m | sed -n '2 p' | awk '{print $3}'`
echo $DT $FR >> $LOG
sleep 1
done
rm -f "$TERMINATORFILE"
To do: Daemonize it
0 Comments