Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mac System Monitor BASH script
01-20-2010, 10:31 AM (This post was last modified: 01-20-2010 10:34 AM by codecaine.)
Post: #1
Mac System Monitor BASH script
Video record your mac with my BASH script.
This script I created takes snap shots of the system screen at interval seconds giving. For example:
Code:
./sys_mon 5

This code will save a snapshot every 5 seconds with a time stamp on the image. Each file is save in a $HOME/sys_monitor that is made with the date it start it was taken. A user can load all the images in a giving folder then put it in I movie and convert it to a movie the the giving time laps.
Code:
#!/bin/bash

############################################################
#System Monitor v1.0 coded by codecaine aka Jerome Scott II#
############################################################

#Error return values
NO_ARGUMENT=1;
FAIL_CREATE_DIRECTORY=2;
INVALID_NUMBER=3;

TIME_STAMP="$1T`date +%s`"; #time stamp for files $1T is the interval seconds for each shot taken appended to it is the timestamp
DATE=`date "+%d-%m-%y"`; #date folder time where files will be sate
SAVE_LOCATION="$HOME/sys_monitor/$DATE"; #location of saved files
FILE_TYPE='.jpg'; #file types
FILENAME="$SAVE_LOCATION/m$TIME_STAMP$FILE_TYPE"; #filename format

#program usage display function
usage()
{
    echo  'Usage';
    echo "     $0 seconds for each snapshot or $0 -k to terminate the program from running";
    echo "Example:"
    echo "     $0 5";
}

#check if input is a number
isNumber()
{
    #Check if user just enter a number. If the number is empty they didn't put in a valid number and the function returns 1 else return 0 on success
    local number=`echo "$1" | sed -n '/^[0-9]*$/p'`
    if [ -z $number ]
    then
        return 1;
    else
        return 0;
    fi
}


#check for atleast 1 arugment entered
if [ $# -lt 1 ]
then
    usage;
    exit $NO_ARGUMENT;
fi

#Stop all instances of this program from from running
if [ "$1" = "-k" ]
then
    echo "kill"
    killall bash
fi

#check for valid input
if ! isNumber $1
then
    usage
    exit $INVALID_NUMBER;
fi

#check if the directory exist
if [ -d $SAVE_LOCATION ]
then
    echo "Monitored files saving: $SAVE_LOCATION";
    screencapture -x $SAVE_LOCATION;
else
    if mkdir $SAVE_LOCATION
    then
        echo "Monitored files saving: $SAVE_LOCATION";
    else
        echo "Failed to directory to to store files";
        exit $FAIL_CREATE_DIRECTORY;
    fi
fi

while true
do
    #sleep for a giving amount time before the next snapshot
    sleep $1;
    #update time stamp
    TIME_STAMP="$1T`date +%s`";
    #update filename
    FILENAME="$SAVE_LOCATION/$TIME_STAMP$FILE_TYPE";
    screencapture -x "$FILENAME";
done


Attached File(s)
.zip  sys_mon.zip (Size: 1.06 KB / Downloads: 2)
Visit this user's website Find all posts by this user
Quote this message in a reply
01-20-2010, 07:24 PM
Post: #2
RE: Mac System Monitor BASH script
It is good how you made that input check and usage.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: