Here are two simple Korn shell scripts you can cron to monitor things on your linux server :) Modified from scripts I use on my own servers at home.

::::::::::::::
 filemonitor.ksh
 ::::::::::::::
 #!/usr/bin/ksh
 #This script monitors the watched_dir for files matching the watched_filter and
 #sends email when new files how show up
script_dir=/path/to/script
 datestamp=`date '+%Y%m%d%H%M%S'`
watched_dir=/path/to/watched_dir
 watched_filter=file_
 email_subj="ALERT: Files Waiting in Watched Directory"
 email_to="email1@domain.com,email2@domain.com"
cd $script_dir
ls -1 -d $watched_dir/*.* | grep $watched_filter > current_files
if [ -f last_files ]
 then
diff current_files last_files | grep "<" |awk '{printf("%s\n",$2)}' > notify_files
 else
 cp current_files notify_files
 fi
 line_count=`wc -l notify_files|awk '{print $1}'`
 if [ $line_count -gt 0 ]
 then
 files=`cat notify_files`
 more $files >  files.txt
mail -s "$email_subj" "$email_to" < files.txt
 fi
 mv current_files last_files
 mv files.txt filearc/files_$datestamp.txt
 rm notify_files
 cd -
::::::::::::::
 checkwebsite.ksh
 ::::::::::::::
 #!/usr/bin/ksh
#This script monitors a webpage and if it changes more than (100 - alert_percent)
 #sends email to the listed people
 script_dir=/path/to/script
 script_dir=/usr/local/transfer/data/reports/ops/notifyscript
 datestamp=`date '+%Y%m%d%H%M%S'`
url_to_check="domain.com/webpage"
alert_percent=80
email_subj="ALERT: Monitored WebPage <$url_to_check>"
 email_to="email1@domain.com,email2@domain.com"
cd $script_dir
wget -q -O current_website $url_to_check
if [ -f last_website ]
 then
total_lines_current=`wc -l current_website | awk '{print $1}'`
 total_lines_last=`wc -l last_website | awk '{print $1}'`
 total_nonmatch_lines=`diff current_website last_website|egrep '^[<>]+' |  wc -l`
total_nonmatch_lnc=`expr $total_nonmatch_lines \* 100`
 total_nonmatch_pctg=`expr $total_lines_current + $total_lines_last`
 total_nonmatch_pctg=`expr $total_nonmatch_lnc / $total_nonmatch_pctg`
 total_match_pctg=`expr 100 - $total_nonmatch_pctg`
if [ $total_match_pctg -lt $alert_percent ]
 then
echo "The monitored webpage <$url_to_check> is more than $total_nonmatch_pctg% different than the stored copy from last run, the threshold is $alert_percent%." |  mail -s "$email_subj" "$email_to"
echo $total_nonmatch_pctg
 fi
 fi
mv current_website last_website
 cd -
Enhanced by Zemanta

image

The first rule of dog club, tell non dog owners about dog club, so that they too will want to join dog club. My friend Amer wrote a post describing the ‘Secret Dog Owners Club‘, and I totally agree. Having a dog has been a very interesting experience for me. I have met neighbors I didn’t know existed and have explored parts of Lewisville I feel remiss for not knowing about in the several years I have lived here.

I have discovered the awesomeness of the dog park, if you haven’t been and you have a dog you NEED to go. There is something cool about meeting friendly people you inherently share experiences with. I have met some of the best people I have met in a long time at the dog park. It is not just the dog park either, even in my own apartment complex my dog and I witnessed supermoon, enjoyed the awesomeness of an early morning walk along the belt of greenery that spans the edge of the complex. I have met many of my neighbors and learned about cool dog things going on in and around Lewisville all while enjoying being outside with my buddy, Gunner.

This may be a secret club, but it isn’t all that exclusive; all it requires is that you have a dog and are willing to be a good dog owner.

Enhanced by Zemanta

image

Well, I don’t miss the letter C, for my non technical readers, that would be silly; I miss the idea of the C language. And while I know as a programmer who makes my paycheck with Java and scripting languages, that this admission it is tantamount to blasphemy, I miss the power, the structure… for goodness sake I miss pointers. That is the point where the audience is supposed to groan and do the ‘ooooohhhh!?!?’ thing. I miss seg faults and cleaning up my own memory. C was my first ‘big boy’ language, and I miss it.

Enhanced by Zemanta

ULC – Useful Linux Commands

 kill -9 `ps -elf | grep<search string>” | awk ‘{printf(“%s “,$4);}’`

And to break it down:

 kill -9 [Kill processes sending signal 9, extreme prejudice] `ps -elf [list processes e: all running processes l: long format f: full output format] | grep “<search string>”[ filter to only processes matching only the prvided search string] | awk ‘{printf(“%s “,$4);}[output the 4th column of the previous commands (this may be different based on distro/flavor) on a single line separated by spaces. The printf command in Awk works very much like the old C printf, the first argument is your format string, following arguments are your data. %s says to print a string, $4 refers to the fourth column delimited by the default feild separator ' ', a space.]‘` [again `` tells the shell to evaluate the contained commands and use them in the command containing ``]

Enhanced by Zemanta

ULC – Useful Linux Commands

I decided to start doing this to help out my Linux challenged friends with linux command structure and a few commands I use on a regular basis, sometimes commands are overly complicated to demonstrate utilities that exist in Linux to make your life easier.

This command is more complicated than it needs to be*, but I was in a rush:

 ls -lrt `grep -i “<string goes here>” * | awk ‘{FS=”:”};{print $1}’

And to break it down:

ls [list] -lrt [ l: long listing, r: reverse sort order, t: sort by modified time] `grep -i [ search for the following string i: without regard to case] “<string goes here>” *  [*: in all files] awk   [awk is great for breaking data into columns and displaying what you need] ‘{FS=”:”} [set the feild separator to : , see the output of grep] {print $1}’ [output the first column]`[`` in a linux command tells the shell to evaluate the command and include the results]

 

* This could also be accomplished with the following:

 ls -lrt `grep -li “<string goes here>” *`

Enhanced by Zemanta

image

A few weeks ago, well in reality a few months ago I decided I really wanted a dog. My justification was that he’d be a built in workout partner. I kinda flip flopped on this a bit and looked at low energy puppies. I kinda knew they wouldn’t fulfil my need for a workout buddy but they were cute and cuddly and that’s a great reason to get a dog. So far, am enjoying dog ownership; I think we may be training each other. I am definitely feeling healthier, it is nice to be actually outdoors more; we’ll see how that feels when the full brunt of the Texas summer is upon us. As of this writing, I have lost 11lbs without significant change to what i have been eating. Generally i walk gunner about 2 miles a day with a bit longer of a walk on Saturday.

image

Gunner and I met my friend Sharon and her dog Dodgy at Central Park here in Lewisville for a doggy play date. We all had a good.time and Gunner is WIPED, walked a bunch and then let them play a bit. Good times with good dogs.

Meet Gunner, he is my 10 month old german short haired pointer/lab mix. I adopted Gunner, with the help of my friend Carrie, from the City of Lewisville Animal Shelter.  Gunny, as I call him for short, is pretty relaxed, this was a pretty big draw to him at the pound. He is a good dog and is coming along pretty well on the journey to being balanced and happy.

Enhanced by Zemanta