Bash swap function for swapping two files

Published on Author admin

Put following function definition code into ~/.bashrc file: function swap()         {     local TEMPFILENAME=tempfile.$$     mv "$1" $TEMPFILENAME && mv "$2" "$1" && mv $TEMPFILENAME $2 } Usage: swap FILE1 FILE2 This solution was originally found at: https://stackoverflow.com/questions/1115904/shortest-way-to-swap-two-files-in-bash/1115909#1115909

Port forwarding using HAproxy

Published on Author admin

HAproxy can be used not only for complex load-balancing scenarios, but also for simple port forwarding. Useful for forwarding packets originating from both local and external hosts. listen postgresql 0.0.0.0:5432     mode tcp     stats enable     balance roundrobin     server postgresql-db 192.168.0.1:5432 check

SSH connection inside while Bash loop

Published on Author admin

When using SSH connection inside while Bash loop, there is need to redirect SSH input to /dev/null, as SSH reads standard input by default: #!/bin/bash while read IP; do echo $IP; ssh root@$IP -C hostname < /dev/null; echo "" done < ip.txt Contnet of ip.txt file: 192.168.0.10 192.168.0.11 192.168.0.12

Creating AWS EC2 instances from CLI

Published on Author admin

Install Python PIP: yum install python-pip or yum install python3-pip Install AWS CLI using PIP: pip install awscli --user or pip3 install awscli --user PIP installs aws inside $HOME/.local/bin/ directory. Configure $PATH inside ~/.bash_profile PATH=$PATH:$HOME/bin:$HOME/.local/bin Configure AWS client: $ aws configure AWS Access Key ID [None]: AWSACCESSKEYID AWS Secret Access Key [None]: AWSSECRETACCESSKEY Default region… Continue reading Creating AWS EC2 instances from CLI