linux

Configure proxy

export http_proxy=http://10.203.0.1:5187/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

cat <> /etc/environment
export http_proxy="http://${PROXY_USER}:${PROXY_PASS}@192.168.0.222:8080"
export https_proxy="http://${PROXY_USER}:${PROXY_PASS}@192.168.0.222:8080"
export no_proxy="localhost,127.0.0.1,foo.example.com"
EOF

cat < /etc/apt/apt.conf.d/12proxy
Acquire::http::Proxy "http://${PROXY_USER}:${PROXY_PASS}@192.168.0.222:8080";

Install prometheus under Ubuntu

Install from repository
sudo apt-get install -y prometheus
# optional
sudo apt-get install -y prometheus-node-exporter
sudo apt-get install -y prometheus-alertmanager
sudo apt-get install -y prometheus-pushgateway

Ansible installation
https://github.com/panticz/ansible/tree/master/roles/prometheus
- hosts: localhost
roles:
- prometheus

Login
http://SERVER_IP:9090/

Commands
avg_over_time(node_memory_MemAvailable[5m])/1024/1024

Repositroy

Nginx access control / GeoIP

cat < /etc/nginx/conf.d/geoip.conf
geoip_country /usr/share/GeoIP/GeoIP.dat;

map $geoip_country_code $allowed_country {
default no;
DE yes;
CH yes;
}

log_format allow "allow $remote_addr;";
EOF
chmod 644 /etc/nginx/conf.d/geoip.conf

cat < /usr/local/bin/nginx-allow
#!/bin/bash

while inotifywait --quiet --event create,delete --exclude "[^c][^o][^n][^f]$" /tmp
do
/usr/sbin/nginx -t && /usr/sbin/service nginx reload
done
EOF
chmod 755 /usr/local/bin/nginx-allow

cat < /etc/systemd/system/nginx-allow.service
[Unit]

VMware Player

<?php
$URL="https://raw.githubusercontent.com/panticz/installit/master/install.vmware-player.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

sudo apt-get install -y open-vm-tools

Links
https://docs.vmware.com/en/VMware-Workstation-Player/12.0/com.vmware.player.linux.using.doc/GUID-42F4754B-7547-4A4D-AC08-353D321A051B.html

openconnect

echo pass1234 | openconnect --no-cert-check vpn.example.com --user foo

start-stop-daemon --start --make-pidfile --pidfile "${VPNPID}" \
--stderr "${VPNERRFILE}" --stdout "${VPNLOGFILE}" \
--background --exec /bin/bash \
-- -c "exec /usr/sbin/openconnect --pid-file=\"${VPNPID}\" ${!VPNOPTS} ${!SERVER} <<< \`echo \"${!PASSWORD}\"\`"

# Custom script
# cat /etc/vpnc/post-connect.d/route
#!/bin/bash

ip route del default
ip route add default via 10.0.17.254
ip route add 120.1.0.0/16 dev tun0 scope link

rsync

On-the-fly backup (backup a running system)
sudo rsync -e "ssh -i ${HOME}/.ssh/id_rsa" -av --delete --numeric-ids --exclude=proc/* --exclude=sys/* --exclude=tmp/* root@${HOST}:/ .

limit bandwith to 2 mbit/s
rsync --bwlimit=2000 --delete -avz root@www.example.com:/ /media/backup/www.example.com/$(date -I)/

# Specify SSH key and configuration
sudo rsync -av \
-e "ssh -i /home/foo/.ssh/id_rsa -F /home/foo/.ssh/config" \
--delete \
--numeric-ids \
-av \
/from/dir/ root@192.168.0.1:/to/dir

--ignore-times

find

# find files without read / write permissions for other
find /media/foo /media/bar ! -perm -o+rw -exec ls -l {} \;
find /media/foo /media/bar -ctime -1 -type f ! -perm -go+rw -exec chmod a+rw {} \;
find /media/foo /media/bar -1 -type d ! -perm -go+rwx -exec chmod 777 {} \;

# find all empty files
find /tmp -type f -empty

# find empty directories
find . -type d -empty

# print file content
find ./ -type f | while read f; do printf "\n# file %s\n" "$f"; cat "$f"; done

# find files by date
find /path/to/dir -newermt "yyyy-mm-dd"

# list all files modified on given date