Benutzer-Werkzeuge

Webseiten-Werkzeuge


shelltricks

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Nächste Überarbeitung
Vorherige Überarbeitung
shelltricks [2020-02-10 22:03] – angelegt fanirshelltricks [2021-08-02 14:19] (aktuell) fanir
Zeile 2: Zeile 2:
  
 Miscellaneous small shell scripts that I may or may not need again in the far future. Miscellaneous small shell scripts that I may or may not need again in the far future.
 +
  
 ===== Check umask for all users ===== ===== Check umask for all users =====
Zeile 9: Zeile 10:
  
 for user in $(awk -F: '{print $1}' /etc/passwd); do for user in $(awk -F: '{print $1}' /etc/passwd); do
-    printf "%-20s" "$user" ; su -p -s /bin/bash -c 'umask' -l $user 2>/dev/null+    printf "%-20s" "$user" ; su -s /bin/bash -c 'umask' -l $user 2>/dev/null
 done done
 </code> </code>
  
 Original source: https://unix.stackexchange.com/a/82645 Original source: https://unix.stackexchange.com/a/82645
 +
 +
 +===== Show the dates of the oldest unseen messages in multiple maildirs, newest first =====
 +
 +Beware of weird directory names. I am not responsible if this somehow does an ''rm -rf --no-preserve-root /'' or something.
 +
 +<code bash>
 +for dir in /var/vmail/domain/*/Maildir/new /var/vmail/domain/*/Maildir/.*/new; do
 +    echo -e "$(stat -c %y $dir/$(ls -Art $dir | head -1))\t$dir"
 +done | grep -v '/\./' | sort -rn
 +</code>
 +
 +Same thing, but for the newest seen messages:
 +
 +<code bash>
 +for dir in /var/vmail/domain/*/Maildir/cur /var/vmail/domain/*/Maildir/.*/cur; do
 +    echo -e "$(stat -c %y $dir/$(ls -At $dir | head -1))\t$dir"
 +done | grep -v '/\./' | sort -rn
 +</code>
 +
 +The only differences are the folders (''cur'' vs. ''new'') and the sorting done by ''ls''.
 +
 +
 +===== Extract IP addresses from "ip a" output by regex =====
 +
 +Might be useful for scripting, I guess.
 +
 +<code bash>
 +IPRE='192\.168\.1\.|2001:1234:'
 +ip a s up | grep -Eo "inet6? [^ /]+" | cut -d' ' -f2 | grep -E "$IPRE"
 +</code>
 +
 +This prints:
 +
 +<code>
 +192.168.1.123
 +2001:1234:5678:90ab:cdef:1234:5678:90ab
 +</code>
shelltricks.1581368618.txt.gz · Zuletzt geändert: 2020-02-10 22:03 von fanir