How To Restart Apache Using cron If the Load Gets Too High

Author: , February 3rd, 2016

There are times when the hackers slam my servers and the load gets too high. I use a very simple bash script as a cron job to monitor the load and take action when it gets too high. The script will stop httpd, sleep for a configurable period of time (currently 3 minutes), then start […]

How To Eject a Volume from the Terminal Command Line in MacOSX

Author: , December 8th, 2015

As always, YMMV… 1 2 3 4 5 6 7 8 9 #!/bin/bash # Usage: eject [fullpath to mount point] DISK="${1:-/Volumes/YourUSBFlashDriveName/}" df -h "$DISK" > /dev/null 2>&1 if [ $? -eq 0 ]; then    diskutil unmountDIsk `diskutil list "$DISK" | grep ^/dev/` else    echo Volume $DISK is not mounted…skipping. fi #!/bin/bash # Usage: […]

How To Auto-Restart Apache If the Load Gets Too High

Author: , September 15th, 2015

The script to check and restart apache…works on CentOS – YMMV! 1 2 3 4 5 6 7 8 9 10 11 #!/bin/bash MAXLOAD=6 check=$(uptime | awk -F’average: ‘ ‘{print $2}’ | awk ‘{print $1}’ | tr -d ‘,’) if [[ $check > $MAXLOAD ]]; then     /sbin/service httpd stop     HOST=`hostname`   […]

How To Disable the Bash Terminal Bell

Author: , July 7th, 2015

The Readline library has a bell-style variable that controls what happens when Readline wants to ring the terminal bell. If set to ‘none’, Readline never rings the bell. If set to ‘visible’, Readline uses a visible bell if one is available. If set to ‘audible’ (the default), Readline attempts to ring the terminal’s bell. Edit […]

How To: for loops in bash

Author: , February 27th, 2015

1 2 3 4 #!/bin/bash for line in `cat file.txt`; do    echo line: $line done #!/bin/bash for line in `cat file.txt`; do echo line: $line done 1 2 3 4 #!/bin/bash for file in $( ls ); do    echo filename: $file done #!/bin/bash for file in $( ls ); do echo filename: $file […]

How To Add a Column of Numbers Using AWK

Author: , January 1st, 2015

awk ‘{sum+=$1}END{print sum}’ inputFile

How To Patch the ShellShock bash Bug on Older or Beta AWS Linux AMI’s

Author: , October 1st, 2014

This is the standard upgrade method for AWS Linux AMI’s: 1 2 yum clean all yum update bash yum clean all yum update bash Or use this for the version 2012.09, 2012.03, or 2011.09 repositories: 1 2 yum clean all yum –releasever=2013.03 update bash yum clean all yum –releasever=2013.03 update bash For older AWS Linux […]