Check These Out
I like much more the perl solution, but without using perl. It launches a backgroup process that will kill the command if it lasts too much.
A bigger function:
check_with_timeout() {
[ "$DEBUG" ] && set -x
COMMAND=$1
TIMEOUT=$2
RET=0
# Launch command in backgroup
[ ! "$DEBUG" ] && exec 6>&2 # Link file descriptor #6 with stderr.
[ ! "$DEBUG" ] && exec 2> /dev/null # Send stderr to null (avoid the Terminated messages)
$COMMAND 2>&1 >/dev/null &
COMMAND_PID=$!
[ "$DEBUG" ] && echo "Background command pid $COMMAND_PID, parent pid $$"
# Timer that will kill the command if timesout
sleep $TIMEOUT && ps -p $COMMAND_PID -o pid,ppid |grep $$ | awk '{print $1}' | xargs kill &
KILLER_PID=$!
[ "$DEBUG" ] && echo "Killer command pid $KILLER_PID, parent pid $$"
wait $COMMAND_PID
RET=$?
# Kill the killer timer
[ "$DEBUG" ] && ps -e -o pid,ppid |grep $KILLER_PID | awk '{print $1}' | xargs echo "Killing processes: "
ps -e -o pid,ppid |grep -v PID | grep $KILLER_PID | awk '{print $1}' | xargs kill
wait
sleep 1
[ ! "$DEBUG" ] && exec 2>&6 6>&- # Restore stderr and close file descriptor #6.
return $RET
}
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"
Here is a command line to run on your server if you think your server is under attack. It prints our a list of open connections to your server and sorts them by amount.
BSD Version:
$ netstat -na |awk '{print $5}' |cut -d "." -f1,2,3,4 |sort |uniq -c |sort -nr
Converts any number of seconds into days, hours, minutes and seconds.
sec2dhms() {
declare -i SS="$1"
D=$(( SS / 86400 ))
H=$(( SS % 86400 / 3600 ))
M=$(( SS % 3600 / 60 ))
S=$(( SS % 60 ))
[ "$D" -gt 0 ] && echo -n "${D}:"
[ "$H" -gt 0 ] && printf "%02g:" "$H"
printf "%02g:%02g\n" "$M" "$S"
}
Must be run as root.
The 'tomcat' user must have access to the .keystore file.
The key and keystore passwords must be the same.
The password must be entered into the server.xml config file for Tomcat.
Gets the authors, sorts by number of commits (as a vague way of estimating how much of the project is their work, i.e. the higher in the list, the more they've done) and then outputs the results.
video.avi is the resulting file. Press Ctrl+c to stop the recording. You can change the OVC option to another to record into a different format.