Browse Source

* update formatting
* Update apachelog
* Add block-email
* add cpu-spike
* Add find-disabled-sites
* add maillog
* add site-enabled

Nathaniel van Diepen 4 years ago
parent
commit
a839b1dab2
10 changed files with 164 additions and 61 deletions
  1. 39 27
      apachelog
  2. 14 0
      block-email
  3. 15 0
      cpu-spike
  4. 10 10
      create-site
  5. 18 0
      find-disabled-sites
  6. 28 0
      maillog
  7. 20 20
      mysqllog
  8. 16 0
      site-enabled
  9. 2 2
      update
  10. 2 2
      zombies

+ 39 - 27
apachelog

@@ -1,31 +1,43 @@
 #!/bin/bash
 if [[ "$1" = "" ]];then
-	apachelog more;
+  apachelog more;
 else
-	t=$1;
-	shift;
-	case "$t" in
-		search)
-			cat /var/log/apache2/error.log | grep "[email protected]";
-		;;
-		ignore)
-			cat /var/log/apache2/error.log | grep -v "[email protected]";
-		;;
-		tail)
-			if [[ "[email protected]" == "" ]];then
-				tail -f /var/log/apache2/error.log;
-			else
-				tail --lines="[email protected]" /var/log/apache2/error.log;
-			fi;
-		;;
-		more)
-			more /var/log/apache2/error.log;
-		;;
-		flush)
-			echo "" > /var/log/apache2/error.log;
-		;;
-		*)
-			echo "Usage: $0 [{search|ignore|tail|more|flush} <params>]";
-			exit 1;
-	esac;
+  site=$1;
+  shift;
+  if [[ "$1" == "" ]];then
+    t=$site;
+    site="";
+    path="/var/log/apache2/error.log";
+  else
+    t=$1;
+    shift;
+    path="/var/log/apache2/$site.error.log";
+  fi;
+  case "$t" in
+    search)
+      cat $path | grep "[email protected]";
+    ;;
+    ignore)
+      cat $path | grep -v "[email protected]";
+    ;;
+    tail)
+      if [[ "[email protected]" == "" ]];then
+        tail -f $path;
+      else
+        tail --lines="[email protected]" $path;
+      fi;
+    ;;
+    more)
+      more $path;
+    ;;
+    flush)
+      echo "" > $path;
+    ;;
+    sites)
+      ls /var/log/apache2/*.error.log | awk '{print gensub(/\.error\.log$/, "", "g", gensub(/^.*\//, "","g"))}';
+    ;;
+    *)
+      echo "Usage: $0 <site> [{search|ignore|tail|more|flush|sites} <params>]";
+      exit 1;
+  esac;
 fi;

+ 14 - 0
block-email

@@ -0,0 +1,14 @@
+#!/bin/bash
+if [[ $EUID -ne 0 ]]; then # Force root
+  exec sudo $0 "[email protected]";
+fi;
+if [[ "$1" = "" ]];then
+  echo "Usage: $0 <email>";
+else
+  cd /etc/postfix/;
+  echo "$1 REJECT" >> sender_access;
+  postmap hash:sender_access;
+  service postfix restart;
+  service saslauthd restart;
+  service courier-authdaemon restart;
+fi;

+ 15 - 0
cpu-spike

@@ -0,0 +1,15 @@
+#!/bin/bash
+fulload(){
+  echo "Starting fork $1";
+  dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null &
+};
+start=1;
+if [ "$1" != "" ];then
+  for (( i=$start;i<=$1;i++ )); do
+    fulload $i;
+  done;
+else
+  fulload 1;
+fi;
+read;
+killall dd;

+ 10 - 10
create-site

@@ -1,24 +1,24 @@
 #!/bin/bash
 if [[ $EUID -ne 0 ]]; then # Force root
-	exec sudo $0 "[email protected]";
+  exec sudo $0 "[email protected]";
 fi;
 if [[ "$1" == "" ]];then
-	echo "Usage: $0 site [target]";
-	exit 1;
+  echo "Usage: $0 site [target]";
+  exit 1;
 fi;
 site=$(basename $1);
 ROOT=$(dirname $(realpath $0));
 if [[ "$2" == "" ]];then
-	echo "Creating site directory";
-	mkdir -p /var/www/$site;
+  echo "Creating site directory";
+  mkdir -p /var/www/$site;
 else
-	echo "Creating site symlink";
-	ln -s "$2" "/var/www/$site";
+  echo "Creating site symlink";
+  ln -s "$2" "/var/www/$site";
 fi;
 if [[ ! -f /etc/apache2/sites-available/$site.conf ]]; then
-	echo "Creating site config";
-	cp $ROOT/default.site.conf /etc/apache2/sites-available/$site.conf;
-	sed -i "s/__SITE__/$site/" /etc/apache2/sites-available/$site.conf;
+  echo "Creating site config";
+  cp $ROOT/default.site.conf /etc/apache2/sites-available/$site.conf;
+  sed -i "s/__SITE__/$site/" /etc/apache2/sites-available/$site.conf;
 fi;
 a2ensite $site;
 service apache2 reload;

+ 18 - 0
find-disabled-sites

@@ -0,0 +1,18 @@
+#!/bin/bash
+main(){
+  pushd /var/www/ > /dev/null;
+  ls | while read site;do
+    site="$(echo $site | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g')";
+    if [ -d $site ];then
+      site-enabled "$site" > /dev/null;
+      if [ $? -ne 0 ];then
+        echo "$site is not enabled";
+      fi;
+    else
+      echo "$site is not a directory";
+    fi;
+  done;
+  popd > /dev/null;
+  unset -f main;
+}
+main;

+ 28 - 0
maillog

@@ -0,0 +1,28 @@
+#!/bin/bash
+if [[ "$1" = "" ]];then
+  apachelog more;
+else
+  t=$1;
+  shift;
+  case "$t" in
+    search)
+      cat /var/log/mail.log | grep "[email protected]";
+    ;;
+    ignore)
+      cat /var/log/mail.log | grep -v "[email protected]";
+    ;;
+    tail)
+      if [[ "[email protected]" == "" ]];then
+        tail -f /var/log/mail.log;
+      else
+        tail --lines="[email protected]" /var/log/mail.log;
+      fi;
+    ;;
+    more)
+      more /var/log/mail.log;
+    ;;
+    *)
+      echo "Usage: $0 [{search|ignore|tail|more} <params>]";
+      exit 1;
+  esac;
+fi;

+ 20 - 20
mysqllog

@@ -1,25 +1,25 @@
 #!/bin/bash
 if [[ "$1" = "" ]];then
-        mysqllog more;
+  mysqllog more;
 else
-        t=$1;
-        shift;
-        case "$t" in
-                search)
-                        cat /var/log/mysql/error.log | grep "[email protected]";
-                ;;
-                ignore)
-                        cat /var/log/mysql/error.log | grep -v "[email protected]";
-                ;;
-                tail)
-                        tail --lines="[email protected]" /var/log/mysql/error.log;
-                ;;
-                more)
-                        more /var/log/mysql/error.log;
-                ;;
-                *)
-                        echo "Usage: $0 [{search|ignore|tail|more} <params>]";
-                        exit 1;
-        esac;
+  t=$1;
+  shift;
+  case "$t" in
+    search)
+      cat /var/log/mysql/error.log | grep "[email protected]";
+    ;;
+    ignore)
+      cat /var/log/mysql/error.log | grep -v "[email protected]";
+    ;;
+    tail)
+      tail --lines="[email protected]" /var/log/mysql/error.log;
+    ;;
+    more)
+      more /var/log/mysql/error.log;
+    ;;
+    *)
+      echo "Usage: $0 [{search|ignore|tail|more} <params>]";
+      exit 1;
+  esac;
 fi;
 

+ 16 - 0
site-enabled

@@ -0,0 +1,16 @@
+#!/bin/bash
+readonly ARGS="[email protected]";
+main(){
+  local code=0;
+  local site="$(echo $1 | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g')";shift
+  local output="$(apachectl -S 2> /dev/null)";
+  if [[ "$(echo $output | grep "$site")" != "" ]];then
+    echo "Enabled";
+  else
+    echo "Not Enabled";
+    code=1;
+  fi;
+  unset -f main;
+  exit $code;
+}
+main $ARGS;

+ 2 - 2
update

@@ -1,7 +1,7 @@
 #!/bin/bash
 if [[ $EUID -ne 0 ]];then
-	sudo $0 [email protected];
-	exit;
+  sudo $0 [email protected];
+  exit;
 fi;
 echo "Updating local lists";
 apt-get update;

+ 2 - 2
zombies

@@ -1,5 +1,5 @@
 #!/bin/bash
 ps aux | awk '{ print $8 " " $2 }' | grep -w Z | awk '{ print $2 }' | while read pid; do
-	echo "PID: $pid";
-	pstree $pid;
+  echo "PID: $pid";
+  pstree $pid;
 done;