User Tools

Site Tools


docs:tips_n_tricks:snippets.html

Snippets of Information

(to be sorted later)

Ethernet MAC Addresses

xenethernetnetwork

I conclude, that software generated MAC addresses in the Xen context need to start with

00:16:3e:xx:xx:xx
printf '00:16:3e:%02x:%02x:%02x\n' $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256))
ip link set $IFACE address $HWADDR

or1)

x2-xx-xx-xx-xx-xx
x6-xx-xx-xx-xx-xx
xa-xx-xx-xx-xx-xx
xe-xx-xx-xx-xx-xx
printf '%02x:%02x:%02x:%02x:%02x:%02x\n' $(( (RANDOM%256 | 0x02) & 0xfe )) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256))
ip link set $IFACE address $HWADDR

SSH Host Key Fingerprints

ssh

ssh-keygen -lf <pub key file>

The part to be entered at the ssh prompt when connecting to unknown hosts is after the number, i.e. starting with the alg. specifier and need not contain the comment.

less in screen

screenlessipfire

~/.screenrc
# workaround for the glitch, that "less" inside "screen" 5 on 
# "ipfire" 2.29 shows blinking text instead of reverse video:
setenv LESS_TERMCAP_so ^[[7m
setenv LESS_TERMCAP_se ^[[27m
:
:

Credits: ChatGPT

Using $(...) in Nagios'/Icingas command_line

nagiosicingabash

$ needs to be escaped by a second $$

/etc/icinga/commands.cfg
   command_line /usr/local/bin/send_something.sh "$$(printf '%s\n%s' '$HOSTNAME' '$HOSTOUTPUT')"

Credits: Nagios Object Definitions at old-www-mathrice.pages.math.cnrs.fr (Well actually that was the first relevant Startpage hit after ChatGPT failed completely)
Reference: Command Definition - The primary source of the above

Notifications via ntfy at every login

ntfypam

/etc/pam.d/common-session
:
session default=ignore pam_exec.so quiet /bin/sh -c [ test 'open_session' = "$PAM_TYPE" && /usr/bin/wget -q -O /dev/null --post-data "$PAM_USER hat sich gerade von $PAM_RHOST über $PAM_TTY eingeloggt" --header "X-Title: Login" --header "X-Priority: 4" --header "X-Tags: unlock" https://ntfy.sh/my_ntfy_topic]

$PAM_TTY will be ssh when appropriate

References:

  • man 5 pam.conf
  • man 8 pam_exec

What's happening on port X?

lsofnetwork

lsof -iUDP:5353
lsof -iTCP:22

Refactor rcs Versioning respecting comments

shellbashrcs

for i in `seq 1 17`
do
  rlog -r1.2.1.$i /etc/RCS/fstab,v > /tmp/work/log/1.2.1.$i
  co -u -M -r1.2.1.$i /etc/RCS/fstab,v
  log=$( ( egrep -m1 '^date: .*author:.*state:' ; sed '$d' | fgrep -v '*** empty log message ***' ) < /tmp/work/log/1.2.1.$i | sed '1d' )
  rcs -l1 /etc/RCS/fstab,v
  ci -d -m"$log" /etc/RCS/fstab,v
done
diff  <(rlog -r1 /etc/RCS/fstab,v )  <(rlog -r1.2.1 /etc/RCS/fstab,v )
for i in `seq 17 -1 1`
do
  j=$(( i+2 ))
  rcsdiff -r1.2.1.$i -r1.$j /etc/RCS/fstab,v \
  && rcs -o1.2.1.$i /etc/RCS/fstab,v
done

Make bash remember all whitespace including newlines when typing in multiline commands

bash

shopt -s lithist

Make zsh split variable contents at whitespace

zsh

setopt shwordsplit

Make less display things coloured

shelllessdiff

apt install --no-install-recommends source-highlight colordiff ccze
export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s"
export LESS="-R"
less  index.php
rcsdiff index.php | colordiff | less -SRF
rlog index.php | ccze -A | less -SRF

Getting the serial number of my Laptop

~ # dmidecode -s system-serial-number                      

Remove disconnected but still visible USB disks

linuxUSBudev

udevadm trigger
# ? # udevadm trigger --action=add 
echo 1 > /sys/class/block/sd[x]/device/delete

PDF

Split

(unverified suggestions by ChatGPT for future reference)

qpdf input.pdf --split-pages output-%d.pdf
pdfseparate input.pdf page-%d.pdf # poppler
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH \
 -dFirstPage=1 -dLastPage=1 \
 -sOutputFile=page1.pdf input.pdf
pdftk input.pdf burst output page-%02d.pdf

Compress

-
mkdir orig gs
mv -iv *.pdf orig
cd orig
for file in *.pdf
do
  echo "$file"
  gs -sDEVICE=pdfwrite        \
     -dCompatibilityLevel=1.4 \
     -dPDFSETTINGS=/ebook     \
     -dNOPAUSE                \
     -dQUIET                  \
     -dBATCH                  \
     -sOutputFile="../gs/$file" "$file"
done
cd ..

Credits: ChatGPT (for the ghostscript part)

ChatGPT:

Yes. In fact, you don't need to split the PDF into individual pages at all.

pdfwrite operates on the entire document, processing every page in sequence. The compression, image downsampling, font handling, and object optimization are all applied across the whole PDF.

Combine / Merge

(unverified suggestions by ChatGPT for future reference)

qpdf --empty --pages page-*.pdf -- output.pdf
pdfunite page-*.pdf merged.pdf
gs -dBATCH -dNOPAUSE -q \
 -sDEVICE=pdfwrite \
 -sOutputFile=merged.pdf \
 page-*.pdf
pdftk page-*.pdf cat output merged.pdf

iSCSI

Restrict tgtd to localhost

tgt.service.diff
--- /lib/systemd/system/tgt.service     2024-10-27 17:11:29.000000000 +0100
+++ /etc/systemd/system/tgt.service     2025-09-03 00:53:02.340942350 +0200
@@ -1,23 +1,26 @@
 [Unit]
 Description=(i)SCSI target daemon
 Documentation=man:tgtd(8)
 After=network.target
 
 [Service]
 Type=notify
 TasksMax=infinity
 ExecStart=/usr/sbin/tgtd -f
 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v offline
+ExecStartPost=/usr/sbin/tgtadm --lld iscsi --mode portal --op delete --param portal=0.0.0.0:3260
+ExecStartPost=/usr/sbin/tgtadm --lld iscsi --mode portal --op delete --param portal=[::]:3260
+ExecStartPost=/usr/sbin/tgtadm --lld iscsi --mode portal --op new --param portal=127.0.0.1:3260
 ExecStartPost=/usr/sbin/tgt-admin -e -c /etc/tgt/targets.conf
 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v ready
 
 ExecStop=/usr/sbin/tgtadm --op update --mode sys --name State -v offline
 ExecStop=/usr/sbin/tgt-admin --offline ALL
 ExecStop=/usr/sbin/tgt-admin --update ALL -c /dev/null -f
 ExecStop=/usr/sbin/tgtadm --op delete --mode system
 
 ExecReload=/usr/sbin/tgt-admin --update ALL -c /etc/tgt/targets.conf
 Restart=on-failure
 
 [Install]
 WantedBy=multi-user.target
docs/tips_n_tricks/snippets.html.txt · Last modified: 02.09.2026 12:11 CEST by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki