Skip to content

Instantly share code, notes, and snippets.

@ole-tange
ole-tange / racecondition.sh
Last active March 25, 2022 15:50
Show mixing can happen with echo/printf - even if the argument is less than 4 KB
#!/bin/bash
# Show that mixing of output can occur with 'echo' with less than 4 KB argument
echo testing echo - any output indicates that mixing has taken place.
# Generate 20000 lines with: echo aa...a &
# echo bb...b &
# where aa...a = 4000 a's, and bb...b = 4000 b's.
perl -e '$a="a"x4000; $b="b"x4000; for(1..10000) { print "echo $a &\n echo $b &\n" }' |
# Execute them. Because of '&' the commands will run in parallel
@ole-tange
ole-tange / alexamontor.sh
Created April 24, 2018 23:13
Monitor top-10000 hosts from different places in the world. Give output of change.
#!/bin/bash
open_dns() {
# Look for open DNS at X.X.Y.Y
parallel -j0 --tag host -t a youtube.com {1}.{1}.{2}.{2} ::: {1..255} ::: {1..255} |
grep 'youtube.com has address' |
perl -pe 's/^(\d+) (\d+)\t.*/$1.$1.$2.$2/'
}
if [ ! -e open_dns_list ] ; then
@ole-tange
ole-tange / ordinal.txt
Created April 23, 2018 21:58
Ordinal numbers 1..9999th
first
second
third
fourth
fifth
sixth
seventh
eighth
ninth
tenth
abildstrup adolphines bartholine brunhildes bulgariens christabel
columbines galionsvej hieronymus hildeborgs kalundborg leonhardts
limfjorden lunderskov mickeysoft reinholdts rejnholdts tulipanvej
uzbekistan adjunkters adoptering adverbiums afblomstre afguderisk
afhjemling afkoblings afmeldings afskyeligt afspejling aftensbord
afveksling agentfilms agnostiker agurketids akronymets albuminers
albuminets algoritmen algoritmes alkymisten alkymister almengjort
altmodisch altruismen amnestilov amplituden amplituder amplitudes
amputering andetsprog angerfuldt anisbolche anskueligt antilopers
antipoders arbejdsfil arbejdsliv arbejdsomt arbejdstog armbindets
$ cat ls-dev-disk-by-uuid
lrwxrwxrwx 1 root root 10 Apr 27 01:13 /dev/disk/by-uuid/09ecdc0d-0d37-4e21-b771-6176b30ae002 -> ../../sda5
lrwxrwxrwx 1 root root 10 Apr 27 01:13 /dev/disk/by-uuid/9ff8d3c8-e58a-4ba1-b8b3-f6a58e2c04a9 -> ../../dm-6
lrwxrwxrwx 1 root root 10 Apr 27 01:13 /dev/disk/by-uuid/cf998061-fa83-4c11-94ae-ca1b9b955180 -> ../../sda1
lrwxrwxrwx 1 root root 9 Apr 27 01:13 /dev/disk/by-uuid/d6e16359-2a8a-4fe7-9523-f6864aa7555e -> ../../sdb
lrwxrwxrwx 1 root root 10 Apr 27 01:13 /dev/disk/by-uuid/ef010918-29a9-4bd0-aee5-6dd621ec5d84 -> ../../dm-1
lrwxrwxrwx 1 root root 10 Apr 27 01:15 /dev/disk/by-uuid/FD48-E073 -> ../../sdc1
$ cat journalctl-xb
-- Logs begin at Thu 2017-04-27 01:09:36 CEST, end at Thu 2017-04-27 01:11:52 CEST. --
@ole-tange
ole-tange / ssh timig
Created January 30, 2013 10:12
ssh timing
1359540606.28613. OpenSSH_6.0p1 Debian-3ubuntu1, OpenSSL 1.0.1c 10 May 2012
1359540606.28622. debug1: Reading configuration data /home/tange/.ssh/config
1359540606.28624. debug1: /home/tange/.ssh/config line 1: Applying options for *
1359540606.28625. debug1: /home/tange/.ssh/config line 19: Applying options for newton
1359540606.28627. debug1: Reading configuration data /etc/ssh/ssh_config
1359540606.28628. debug1: /etc/ssh/ssh_config line 19: Applying options for *
1359540606.28629. debug2: ssh_connect: needpriv 0
1359540606.28631. debug1: Connecting to newton.binf.ku.dk [130.225.211.96] port 24222.
1359540606.28632. debug1: Connection established.
1359540606.28633. debug1: identity file /home/tange/.ssh/id_rsa type 1
This works:
ssh linux.p 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;perl\ -e\ \'\ use\ IO::Poll\;\ \$SIG\{CHLD\}\ =\ sub\ \{\$done\ =\ 1\}\;\ \$p\ =\ IO::Poll-\>new\;\ \$p-\>mask\(STDOUT,\ POLLHUP\)\;\ \$pid=fork\;\ unless\(\$pid\)\ \{setpgrp\;\ exec\ \$ENV\{SHELL\},\ \"-c\",\ @ARGV\;\ die\ \"exec:\ \$\!\\n\"\}\ \$p-\>poll\;\ kill\ SIGHUP,\ -\$pid\ unless\ \$done\;\ wait\;\ exit\ \(\$\?\&127\ \?\ 128+\(\$\?\&127\)\ :\ 1+\$\?\>\>8\)\ \'\ echo\\\ OK\\\;ls\\\ output_to_STDERR\\\ ;
This blocks (does not finish):
ssh solaris.p 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;e