nixcloud status email

this script is ran by cron:

 services.cron = {
   enable = true;
   mailto = "js@lastlog.de";
   systemCronJobs = [
     "0 1 * * * root /root/mysql-backup/mysql-backup.sh &> /dev/null"
     "0 0,6,12,18 * * * root /root/build-new-system.sh &> /dev/null"
     #*     *     *   *    *            command to be executed
     #-     -     -   -    -
     #|     |     |   |    |
     #|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
     #|     |     |   +------- month (1 - 12)
     #|     |     +--------- day of month (1 - 31)
     #|     +----------- hour (0 - 23)
     #+------------- min (0 - 59)
   ];
 };

now the /root/build-new-system.sh script:

    #!/run/current-system/sw/bin/bash
    source /etc/profile

    if [[ $# -eq 0 ]]; then
      v=`$0 bar`
      echo "$v" | sendmail -t
      exit
    fi

    function doExec {
      echo "<h2>$1</h2>"
      echo "<pre>"
      $1 2>&1
      echo "
"
   }
   echo "To: example@example.org
   From: example@example.org
   Subject: nixcloud.io status
   Content-Type: text/html; charset=ISO-8859-1
   "
   echo "<html>"
   doExec "nix-channel --update"
   doExec "nixos-rebuild build"
   doExec "nix-env --list-generations  -p /nix/var/nix/profiles/system"
   doExec "ls -la /nix/var/nix/gcroots/profiles/"
   doExec "dfc"
   echo "</html>"

</pre>

ppp script by Olivier Demah i'm using

if ! ping -c 1 195.154.210.135 >/dev/null 2>&1 ; then
        echo "`date` Connexion is Down !!!" >> /var/log/messages
        export IFACE=`ifconfig | grep ppp0 | awk '{print $1}'`
        echo "Mmm, interface = $IFACE" >> /var/log/messages
        if [ "$IFACE" != "ppp0" ]; then
            echo "`date` Connexion is Really Down!!" >> /var/log/messages
            kill -9 `ps -ef |grep pppd |awk '{ print $2 }'`
            kill -9 `ps -ef |grep pppoa2 |awk '{ print $2 }'`
            rmmod uhci
            sleep 3
            modprobe uhci
            sleep 3
            /usr/local/bin/modem_run -f /usr/local/bin/microcode.bin -m
            pppd call adsl
       fi
fi

another bash script using color codes

#!/bin/bash
RED="\033[0;31m"
GREEN="\033[0;32m"
WHITE="\033[1;37m"
DGRAY="\033[0;37m"
nmap -p 80 serverkommune.de | grep open > /dev/null
state=$?
if [ $state -eq 0 ]; then
       echo -en "$WHITE"
       echo -e "Status: $GREEN -> apache up, try to get serverkommune homepage"
       echo -en "$DGRAY"
       curl -s serverkommune.de | grep -i bude > /dev/null
       state=$?
       if [ $state -eq 0 ]; then
               echo -en "$WHITE"
               echo -e "Status: $GREEN -> fine -> found word 'bude' on the main html page!"
       else
               echo -en "$WHITE"
               echo -e "Status: $RED !> Couldn't get the main html page or word 'bude' has vanished from it!"
       fi
       echo -en "$DGRAY"
else
       echo -en "$WHITE"
       echo -e "Status: $RED !> apache down for some unknown reason, please repair NOW"
       echo -en "$DGRAY"
fi

argc and argv with bash

if [ ${#} -ne 2 ]; then

   echo "Usage $0 xsize ysize"
   echo "Example: $0 3 5"
   exit

fi

argc is ${#}

argv is ${0} ${1} ${2} ${...}

Powered by MediaWiki