Run a Tor Bridge on Ubuntu

RunAsDaemon 1
BridgeRelay 1
ORPort 16001
ServerTransportPlugin obfs4 exec /usr/bin/obfs4proxy
ServerTransportListenAddr obfs4 0.0.0.0:16002
ExtORPort auto
ContactInfo example@gmail.com
Nickname yourNickname
PublishServerDescriptor 0

References
https://community.torproject.org/relay/setup/bridge/debian-ubuntu/
https://scottlinux.com/2016/01/16/how-to-run-a-tor-bridge-on-linux/
https://tails.boum.org/doc/first_steps/startup_options/bridge_mode/index.en.html

Execute a command whenever a file changes

You can do this with inotifywait utility from inotify-tools package

while true ; do
  inotifywait -e delete_self "/tmp/fileToMonitor.txt" \
    && cp new_file "/tmp/fileToMonitor.txt"
done
[ "$UID" -eq 0 ] || exec sudo "$0" "$@"

while true ; do
  inotifywait -e modify "/etc/resolv.conf" && ./dns.sh
done

References
https://superuser.com/questions/939600/how-to-get-notified-when-a-specific-file-is-deleted-in-linux
https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes
http://man7.org/linux/man-pages/man1/inotifywait.1.html#EVENTS

Command Substitution in bash

Text between backticks is executed and replaced by the output of the command (minus the trailing newline characters, and beware that shell behaviors vary when there are NUL characters in the output). That is called command substitution because it is substituted with the output of the command.

A=`cat /etc/p2ass2wd2 | head -n1`
echo "$A"
A=$(cat /etc/p2ass2wd2 | head -n1)
echo "$A"

References
https://unix.stackexchange.com/questions/48392/understanding-backtick
https://unix.stackexchange.com/questions/147420/what-is-in-a-command

Get IP Address using bash

Displaying private IP addresses

ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/'

address=$(ip addr show wlp3s0 | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')

Displaying the public IP address

If you want to know the public IP address of a Linux server, you can send an HTTP request to one of the following web servers.

  • http://ifconfig.me
  • http://www.icanhazip.com
  • http://ipecho.net/plain
  • http://indent.me
  • http://bot.whatismyipaddress.com
  • https://diagnostic.opendns.com/myip
  • http://checkip.amazonaws.com
curl http://checkip.amazonaws.com
wget -qO- http://checkip.amazonaws.com

References
https://unix.stackexchange.com/questions/119269/how-to-get-ip-address-using-shell-script
https://www.linuxtrainingacademy.com/determine-public-ip-address-command-line-curl/