Various Snippets of Code – Cheatsheet (Work in progress)

Snippets of Code

There are times you don’t remember a command syntax … here are the memory hooks. Work in progress.

AT commands:

ATI - show info
AT+CFUN=0 switch off mobile broadband modem radio.
AT+CFUN=1 switch on radio of a mobile broadband modem.
AT+CFUN=1,1 - fully reset a mobile broadband modem radio.
AT+CNUM - own number
AT+CLAC - list of AT commands



Some tutorials and examples:


show the date of the day that lies 8 days in the future

date -d "+8days"

or next week in UTC

date -d "next week" -u

Show the current date in Unix epochs

date +%s?

Show the day’s date at 2pm, in Unix epochs, that lies eight days in future

date -d "+8days 14:00" +%s

DRUSH (Drupal shell)

  • Update Drupal
drush upc -y && drush updb -y
  • Remove database entries for no longer present modules
drush sql-query "DELETE from system where name = 'image_gallery' AND type = 'module';"


  • list files with suffix .txt, with their file data modified within the last 24 hours.
find . -name "*.txt" -mtime -1
  • list files with suffix .txt, with their file status modified within the last 24 hours.
find . -name "*.txt" -ctime -1
  • list files with suffix .txt, that have been accessed within 24 hours (1*24)
find . -name "*.txt" -atime -1


LETSENCRYPT - create (beta) certificates

./letsencrypt-auto --agree-dev-preview --server auth
  • Automatically configure Apache and Nginx:

letsencrypt run

  • Simply create new certificate:
letsencrypt -d auth
  • Renewing certificate
letsencrypt renew --cert-path example-cert.pem
  • Revoke certificate
letsencrypt revoke
  • Revoke certificate(s) with a particular key.
letsencrypt revoke --cert-path example-cert.pem
letsencrypt revoke --key-path example-key.pem
  • a small variation creating only the domain certs you list (domain list in ~user/lets-encrypt-domains)
./letsencrypt-auto --agree-dev-preview --server `cat ~user/lets-encrypt-domains | sed 's/^/-d /' | tr "\n" " "` auth
  • for nginx use
cat cert.pem chain.pem >> chained-cert.pem
  • Expand a LE-Cert with additional alt names:
certbot-auto certonly --webroot --agree-tos -w /var/www/ \
--expand -d,,


  • Specified key was too long; max key length is 767 bytes

mysql -u USERNAME -p



set global innodb_large_prefix=on;

set global innodb_file_format=Barracuda;

set global innodb_file_per_table=true;



  • remote Certificate checking:
openssl s_client -showcerts -connect

SYMPA (Mailing list service)

  • Look for invalid entries in your clear text database sympa should import:
awk -F' ' '{print $1,$2}' sympa-imported.txt | grep -E -v "\b[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b"
  • Converting newer OpenSSL Keyfiles for use with MariaDB, that expects the old format from OpenSSL 1.0:
    openssl rsa -in "original-key.pem" -out "mysql-key.pem"



  • Clone a running linux system with rsync:

    sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt
  • Variation – Boot target system with grml or similar, set a root password and start ssh, then…
    sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}

TFTP (dnsmasq)

/etc/init.d/network-manager stop; ip link set link up dev eth0 && ip a a dev eth0 && killall -9 dnsmasq; dnsmasq -k --enable-tftp --tftp-root=/var/tftp/
  • For TFTP-Flashing TP-Link TL-WR842NDv1 (filename: wr842ndv1_tp_recovery.bin)
    If flashing is way to slow (takes minutes instead of a couple of seconds, block size negotiation may have failed), see –tftp-no-blocksize.
/etc/init.d/network-manager stop; ip link set link up dev eth0 && ip a a dev eth0 && killall -9 dnsmasq; dnsmasq -k --enable-tftp --tftp-root=/var/tftp/ --tftp-no-blocksize


  • set the file’s (test.txt) date to be yesterday’s date
touch -d `date -d "1 day ago" '+%Y-%m-%d'` test.txt


xmllint --noout --valid abc.xml


related to UUID

  • Alternative to uuidgen command:
cat /proc/sys/kernel/random/uuid
  • setting UUID on device sdx1
tune2fs -U  /dev/sdx1

simple USB reset:

echo 0 > /sys/bus/usb/devices/usb1/authorized
echo 1 > /sys/bus/usb/devices/usb1/authorized

IPv6 “Rosetta Stone”

IPv6 cmd line tool and syntax of various OS compared:

Detecting hidden WIFIs on Linux


airmon-ng start wlan0
airodump-ng mon0

Monitor specific BSSID and Channel:

airodump-ng -c <CHANNEL #> –bssid <BSSID> mon0

Deauthenticate in order to view Reauth with Wireshark:

aireplay-ng -0 30 -a <AP MAC/BSSID> -c <STATION MAC> mon0

(-0 = deauth; 30 = number of deauth tries;)

Wireshark filter for monitoring deauth packets only:

wlan.fc.type_subtype == 0x0c

Notifications and bots

  1. Telegram

/usr/bin/curl –silent -s -X POST “<BOT-ID&gt;:<BOT-SECRET>/sendMessage” -d chat_id=<CHAT-ID> -d text=”Action took place at `/bin/date`” > /dev/null


2. SMTPS Notification with curl



cat head.txt > /tmp/message.txt

echo “Whatever…” >> /tmp/message.txt

cat tail.txt >> /tmp/message.txt

curl url ‘smtps://’ sslreqd mailfrom ‘mail@domain.tld’ mailrcpt ‘mail@domain.tld’ uploadfile /tmp/message.txt user ‘mail@domain.tld:<password>’



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s