Linux Hacks
Mittwoch, 13. Oktober 2021
Symlinks vor dem löschen mit mount bind schützen
Symlinks werden von chattr nicht unterstützt. Mit mount bind statt Symlinks können diese vor dem löschen/ändern geschützt werden.
$ mkdir c d $ echo c>c/ok $ echo d>d/ok $ sudo mount --bind c/ok d/ok $ cat d/ok c $ rm d/ok rm: cannot remove 'd/ok': Device or resource busy
Email mit curl verschicken
1. Textdatei mit Mailbody erstellen
cat << EOF > mail.txt From: klaus@foo.com To: peter@bar.com Subject: Test Hi Peter, Diese Mail habe ich Dir mit curl geschickt. Gruß Klaus EOF
2. Email senden
curl -n --ssl-reqd --user "klaus@foo.com:passwd" --mail-from "<klaus@foo.com>" --mail-rcpt "<peter@bar.com>" --url smtps://smtp.smarthost.com:465 -T mail.txt
Geht auch als Einzeiler
curl -n --ssl-reqd --user "klaus@foo.com:passwd" --mail-from "<klaus@foo.com>" --mail-rcpt "<peter@bar.com>" --url smtps://smtp.smarthost.com:465 -T - <<< $'From: klaus@foo.com\n ...'
Hier das Dollar-Zeichen $ als Prefix vor den Body-String setzen, Damit die Newlines richtig gelesen weden!
Awk als Webserver (gawk)
#!/usr/bin/gawk -f
BEGIN {
if (ARGC < 2) { print "Usage: wwwawk file.html"; exit 0 }
Concnt = 1;
while (1) {
RS = ORS = "\r\n";
HttpService = "/inet/tcp/8080/0/0";
getline Dat < ARGV[1];
Datlen = length(Dat) + length(ORS);
while (HttpService |& getline ){
if (ERRNO) { print "Connection error: " ERRNO; exit 1}
print "client: " $0;
if ( length($0) < 1 ) break;
}
print "HTTP/1.1 200 OK" |& HttpService;
print "Content-Type: text/html" |& HttpService;
print "Server: wwwawk/1.0" |& HttpService;
print "Connection: close" |& HttpService;
print "Content-Length: " Datlen ORS |& HttpService;
print Dat |& HttpService;
close(HttpService);
print "OK: served file " ARGV[1] ", count " Concnt;
Concnt++;
}
}
