unix:misc

Misc.

while true; do nc -l -p 80 -q 1 < error.html; done
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done
python2 -m SimpleHTTPServer 8080
python3 -m http.server 8080
twistd -n web –path .
php -S localhost:8080
pandoc -s -f markdown -t html =(curl https://raw.github.com/cyberhouse/doc/master/README.md) | lynx -stdin
pandoc -s -f markdown -t html doc/README.md | lynx -stdin

curl --header 'Host: www.example.com' 'http://localhost/index.php?id=23&L=5'

curl -d @$HOME/.credentials --cookie-jar /tmp/cjar -k https://example.com/?do=login; curl -k --cookie /tmp/cjar --cookie-jar /tmp/cjar https://example.com/foo|lynx -stdin
curl -s -w "%{http_code}\\n" http://www.cyberhouse.at -o /dev/null
# Add -L if you intend to follow location responses
lsof +D /var/log
nmap -sn 172.16.35.0/24 --script ip-forwarding --script-args="target=www.google.com"
ssh server1 tcpdump -i eth3 -U -s0 -w - 'tcp port 80' | wireshark -k -w /tmp/gw.cap -b filesize:50000 -b files:10 -i -
ssh server1 'tshark -f "port !22" -w -' | wireshark -k -i -
diff .ssh/config <(ssh trillian 'cat .ssh/config')
crontab -l > /tmp/$(whoami)-crontab
echo '* * * * * www-data /var/www/html/typo3/cli_dispatch.phpsh scheduler' >> /tmp/$(whoami)-crontab
crontab /tmp/$(whoami)-crontab
rm /tmp/$(whoami)-crontab
socat TCP4-LISTEN:1234,fork TCP4:192.168.1.1:22' forwards your port   1234 to another machine's port 22. Very useful for quick NAT red
sar -o /tmp/sarlog -A 5 >/dev/null 2>&1
LANG=C; S_TIME_FORMAT="%T; sar -f /tmp/sarlog|les
chattr +i /etc/shadow; lsattr /etc/shadow
chattr -i /etc/shadow; lsattr /etc/shadow
dd if=/dev/zero of=/path/to/swapfile count=2097152 # create 1 G file
mkswap /path/to/swapfile
swapon -p 32767 /path/to/swapfile # use with lowest priority possible

Optionally create an /etc/fstab entry:

/path/to/swapfile none  swap    sw,pri=32767    0   0

Add 1 (after one blank space) or S or Single to the kernel boot parameter to start in single mode. Reset password with passwd check if SELinux is disabled if it does not work (setenforce 0). If single user mode does not work ther is an alternative: Append init=/bin/bash to the boot options, remounting the root partition is necessary (mount -o remount,rw /).

cutter 10.10.0.45
parted /dev/sda # Get the disk size first
dd if=/dev/sda | pv -s 60022480896 | pigz --fast > /media/myExternalDrive/myBackup.img
IMAGE=archlinux-2014.04.01-dual.iso && dd bs=1m if=$IMAGE | /opt/local/bin/pv -s $(wc -c $IMAGE) | dd of=/dev/disk1
tune2fs -l $(df -lh / |(read; awk '{print $1; exit}')) | grep -i created
program=httpd; strace $(ps wuax|grep $program|grep -v grep|awk '{print "-p" $2}'|xargs) -s8192 -r -o /tmp/$program-$(date +%FT%T%z)
echo 1 > /proc/sys/vm/block_dump
ps auxww | sort -nk6
# or 
ps auxww --sort +rss
ps auxwwef
# or to avoid line wraps
ps auxef
hdparm -Tt /dev/sda
stress --vm-bytes $(awk '/MemFree/{printf "%d\n", $2 * 0.9;}'< /proc/meminfo)k --vm-keep -m 1
top -b -i -d 10 >> /tmp/log/top
/bin/bash -c "echo >/dev/tcp/144.76.8.201/443 && echo 'open'"
sudo -U username -l
dstat --top-oom

remotely:

cat /usr/local/www/munin/memory-month.png | gzip -9c | uuencode /dev/stdin

locally:

pbpaste | uudecode -o /dev/stdout | gzip -cd > ~/Downloads/memory-month.png
smbutil statshares -a
dig +short myip.opendns.com @resolver1.opendns.com
curl ipinfo.io
curl ifconfig.me/all
curl icanhazip.com
curl myip.dnsomatic.com
curl whatismyip.akamai.com
vmstat 5 | awk '{system("/bin/echo -n $(/bin/date"); print ": " $0}' | tee vmstat-$(date +%F)
vmstat 5 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
while sleep 3; do curl --silent https://wiki.sysop.cafe/misc|grep sleep && tput bel; done
while sleep 3; do dig foo.bar.baz +short @8.8.8.8|grep 129 && tput bel; done
printf '\a'
echo -en "\007"
tput bel
curl -H "Host: example.com" 10.0.0.13
wget --header="Host: example.com" 10.0.0.13
printf "John:$(openssl passwd -crypt V3Ry)\n" >> .htpasswd # this example uses crypt encryption
printf "Mary:$(openssl passwd -apr1 SEcRe7)\n" >> .htpasswd # this example uses apr1 (Apache MD5) encryption
printf "Jane:$(openssl passwd -1 V3RySEcRe7)\n" >> .htpasswd # this example uses MD5 encryption
(PASSWORD="SEcRe7PwD";SALT="$(openssl rand -base64 3)";SHA1=$(printf "$PASSWORD$SALT" | openssl dgst -binary -sha1 | xxd -ps | sed 's#$#'"`echo -n $SALT | xxd -ps`"'#' | xxd -r -ps | base64);printf "Jim:{SSHA}$SHA1\n" >> .htpasswd) # this example uses SSHA encryption
#!/usr/bin/perl
use strict;
 
chomp(my $filename=$ARGV[0]);
chomp(my $username=$ARGV[1]);
chomp(my $password=$ARGV[2]);
 
if (!$filename || !$username || !$password) {
  print "USAGE: ./crypt.pl filename username password\n\n";
} else {
  open FILE, ">>", $filename or die $!;
  print FILE $username . ":" . crypt($password, $username) . "\n";
  close FILE or die $!;
}
vim -R /var/db/mysql/percona57.err #mysql-error

e.g. to get an progress information for a running program like dd, ping, rsync'.

sed -i -e '3d' ~/.ssh/known_hosts

find /opt/tomcat/temp/ -type f -name '*.xlsx' -mtime +14 -exec rm {} \;

4  5 * * * /usr/local/bin/flock -n /tmp/backup.lock /usr/local/scripts/bbackupfoo.sh

  • unix/misc.txt
  • Last modified: 2019-02-27T12:04:29+0100
  • by Wolfgang