Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

Simple Logger Script

Simple Logger Script

I needed a way to capture some of the Check Point Identity Awareness results periodically.

This captures two commands and puts to a logfile and requires a “source” line. It was written for checkpoint firewall, which requires you to source the profile. Other OS/shells might also require something like the source line to setup your environment, especially if you are running scripts on corporate servers.

#!/bin/bash
# some vendors (check point firewall, requires you to have a "source" line like this
source /top/CPshared/5.0/tmp/.CPpropfile.sh

# specify a format for the date of your choosing
DATE=`/bin/date +%Y%m%d%H%M`

# I ended up using this specific date format
DATESSS=`/bin/date +%Y-%m-%d %H:%M:%S`

LOGFILE=`hostname`_thisdebug.log

# call the 2 commands and store in variable
OUTPUT1=$(some linux command1)
OUTPUT2=$(som other command)

# here we combine into a single variable, so our log file is formatted a specific way
# this allows us to capture two separate commands and put into 1 log file entry
# you could also use 'logger' to add this to syslog, for example
COMBO="$DATESSS,`hostname`,$OUTPUT1,$OUTPUT2"
echo "$COMBO" >> "$LOGFILE"

Both should use crontab -e to set cron for example on minute 1 of every hour, day, week, month

Crontab

01,*,*,*,* /path/to/script.sh

You’ll also need to set the script to executable

chmod +x /path/to/script.sh

Make sure and put the log file on the /tmp/ partition so it will automatically delete itself when it reboots and prevent disk filling up if you forget to stop the test.