www.chris-fritsch.de


crontab
* * * * * <auszuführender Befehl>
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ └──── Wochentag (0-7, Sonntag ist 0 oder 7)
│ │ │ └────── Monat (1-12)
│ │ └──────── Tag (1-31)
│ └────────── Stunde (0-23)
└──────────── Minute (0-59)

Beim reboot bzw. nach dem booten ausführen:
@reboot <auszuführender Befehl>

Folgend Schreibweisen sind in der crontab auch möglich:
@daily <auszuführender Befehl>
@midnight <auszuführender Befehl>
@hourly <auszuführender Befehl>
@weekly <auszuführender Befehl>
@monthly <auszuführender Befehl>
@annually <auszuführender Befehl>
@yearly <auszuführender Befehl>

Alle Ausgaben nach /dev/null umleiten:
* * * * * /pfad/script.sh > /dev/null 2>&1


ssh breaks find-loop in shellscript

#!/bin/bash

DIR=/testdir

find ${DIR} -maxdepth 1 -type f | while read FILE ; do
    # ohne </dev/null wird die Schleife nach dem ersten ssh beendet
    ssh servername "hostname;" </dev/null
done


Scan Network for a Service

nmap -p 22 --open -sV 192.168.0.0/24


Scans 192.168.0.1 - 192.168.0.254 for ssh-server (port 22)
You don't need root access for this


PID-File in bash-script
PID_FILE=/var/run/scriptname.pid

if [ -f $PID_FILE ]
then
    PID=$(cat $PID_FILE)
    ps -p $PID > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
        echo "Process is already running!"
        exit 1
    else
        ## PID-File exists but process not running -> Update PID-File
        echo $$ > $PID_FILE
        if [ $? -ne 0 ]
        then
            echo "Error creating PID-file"
            exit 1
        fi
    fi
else
    echo $$ > $PID_FILE
    if [ $? -ne 0 ]
    then
        echo "Error creating PID-file"
        exit 1
    fi
fi

# ..... rest of the script

# at the end of the script, remove PID-File
rm $PID_FILE

Scrollen im Screen
- Press STRG-A
- Press ESC
- Scroll with UP and DOWN arrow keys
- Press ESC to Exit scrollback-mode

Kill process using grep



kill $(ps -ef | grep 'search' | grep -v grep | awk '{print $2}')
 

or
 

ps -ef |grep 'search' | grep -v grep | awk {'print $2'} | xargs kill
 

or
 

pkill -f search
 

-f The pattern is normally only matched against the process name. When -f is set, the full command line is used.
 

get external-ip



curl ifconfig.me
 

postfix - recipient address regex rewrite

rewrite localpart like google - remove +something from localpart

name+something@domain.tld will go to name@domain.tld

  • add file /etc/postfix/recipient_canonical with content:

    /^(.*)\+(.*)@(.*)$/ ${1}@${3}


  • create the db file with postmap

    postmap /etc/postfix/recipient_canonical


  • add to /etc/postfix/main.cf

    recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical


  • reload or restart postfix

    systemctl restart postfix


  • '
    -->