Autostart script linux

Maak een script aan sudo nano start.sh

#!/bin/sh
sleep 10
cd /
cd home/pi/
sudo python ip.py &
cd /

Wijzig de rechten sudo chmod 775 start.sh

sudo crontab -e
Voeg volgende lijn toe @reboot sudo sh /home/pi/start.sh >/home/pi/logs/cronlog 2>&1

Maak een log file
mkdir logs
chmod 775 logs

Ubuntu opstartscript

TTP IP

# TomTech Productions IP
import time, os
import requests, socket, uuid

## INSERT YOUR KEY AND MAIL HERE ##
domain = "" #company domain
mail = "tom.schelles@live.be" #your email
## INSERT YOUR KEY AND MAIL HERE ##

url = 'https://ttpm.be/data/online/post.php'
mac = uuid.getnode()

def get_lan_address():
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 80))
        return s.getsockname()[0]

while(1):
    lan = get_lan_address()
    name = socket.gethostname()

    myobj = {'lan' : lan, 'mac': mac, 'name': name, 'domain': domain, 'mail': mail }

    try:
        x = requests.post(url, data = myobj)

        if (x.text == "reboot"):
            os.system("shutdown -t 0 -r -f")

        if (x.text == "lock"):
            os.system("shutdown -l")

        if (x.text == "shutdown"):
            os.system("shutdown -t 0 -s -f")

    except:
        print('NO CONNECTION TO SERVICE')
    #update gegevens lokaal om de 10 seconden
    time.sleep(30)

Linux KIOKS mode Chrome

source: https://bloggerbrothers.com/2016/12/27/boot-your-pixel-based-pi-into-chromium-kiosk/

Install following software

sudo apt-get install -y x11-xserver-utils unclutter

Create a new file

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Copy this code into the file

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
#@xscreensaver -no-splash
#@point-rpi
@xset s off
@xset -dpms
@xset s noblank
@sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium/Default/Preferences
@chromium-browser --incognito --noerrdialogs --kiosk tomtechproductions.be/example
@unclutter -idle 0.1 -root
Backup files linux

Backup files linux

An easy way to backup files to a local share

The example backup’s the files from the /var/www/html directory

#change to website folders
cd /var/www/html/

#find all subsites
for D in *; do
    if [ -d "${D}" ]; then
        echo "Generating backup for $D > " `date +%Y-%m-%d_%H-%M-%S`-${D}   # your processing here
        tar -zcvf "/mnt/srv-ttp-nas/server/"`date +%Y-%m-%d_%H-%M-%S`-${D}.tar.gz ${D}
    fi
done

#remove stale files
find /mnt/srv-ttp-nas/server/* -mtime +14 -exec rm {} \;

Add crontab to run backup every night at 3

sudo crontab -e
0 3 * * * /home/tom/backup_files.sh

Preview of data on share

Backup all mysql databases

Backup all mysql databases

I created an easy way to backup all mysql databases
/mnt/srv-ttp-nas/ is a location on a local NAS

#!/bin/sh
sleep 10

DB_USER="username"
DB_PASS="password"
BACKUP_DIR = "/mnt/srv-ttp-nas/bu/databases"

#find all databasses and backup them
databases=`mysql --user=$DB_USER --password=$DB_PASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

for db in $databases; do
        echo "Dumping database: $db"
        mysqldump $db -u $DB_USER -p --password=$DB_PASS | gzip > "/mnt/srv-ttp-nas/databases/"`date +%Y-%m-%d_%H-%M-%S`-$db.sql.gz
done

#remove files older than one month
find /mnt/srv-ttp-nas/databases/* -mtime +31 -exec rm {} \;

The power of this script is that if you add a new database this will automaticly be added.

Add to crontab to backup every 6 hours.

sudo crontab -e
0 0,6,12,18 * * * /home/tom/backup.sh

Preview of data on share

Update Unifi AP using SSH

Update Unifi AP using SSH

Download the correct software from Ubiquiti.

Change the name from the downloaded file to fwupdate.bin

Open WinSCP and connect to the AP using SCP protocol.

Copy the fwupdate.bin file to /tmp folder.

Close WinSCP and open Putty. Connect to the AP using ssh.

Issue the command syswrapper.sh upgrade2 & after this your session will close automatic and the AP will start the upgrade.