Category: shell
-
Unix – Seqential Remote Calls to Several Machines
Copy Data to multiple machines for i in 187 135; do echo “–server${i}–“; scp -p -r /dev/mydata myuser@myhost${i}.net:/dev ; done Execute Scripts in multiple machines Example 1 for i in 187 135; do echo “–server${i}–“; ssh myuser@myhost${i}.net “chmod 777 /dev/mydata.sh;rm -r /dev/main;” ; done Example 2 for i in 187 135; do echo “——de${i}——–“; ssh…
-
Postgres – Executing SQL-Statement in several remote machines sequentially
echo ‘psql -a -d mydatabase -p 5432 -c “\d mytable;”‘| ssh myuser@myserverhost.net ‘sudo su – postgres -c “bash -x — ” ‘ echo ‘psql -a -d mydatabase -p 5432 -c select id from mytable where id = 393050;”‘| ssh myuser@myserverhost.net ‘sudo su – postgres -c “bash -x — ” ‘
-
Unix – vi mini cheat sheet
String Replacement :1,$/s/String1/String2/g Yanking y9y (with : ) -> kopies current and next 9 lines p -> pastes the kopied mentioned lines Yanking using vi – adding files together – copy 30000 lines 30000 yy yy30000 The Yank Command yy make a copy of the current line and place it in the General Purpose Buffer…
-
Unix – Check and Monitor Open Ports and established Connections
lsof -i lsof -i | less # firefox example lsof -i | grep firefox check every second while [ “1” ] ; do clear; lsof -i; sleep 1; done; # firefox example while [ “1” ] ; do clear; lsof -i | grep firefox; sleep 1; done; netstat |grep localhost while [ “1” ] ;…
-
Unix – disk and file size monitoring with du, df and stat
du – file space usage GB sized files and directories du -xh DIRPATH |egrep “^[0-9\.]+[GT]\s” # Examples du -xh ~/ |egrep “^[0-9\.]+[GT]\s” sudo du -xh / |egrep “^[0-9\.]+[GT]\s” Size Of Directory and Disk Space du -s .archived/ du –sk # k: output in in KB # x=> expands, only on the local file system –…
-
Linux – IO Wait History – Sar, Systat
Installation sudo apt-get install -y sysstat IO History ls /var/log/sysstat/sa[0-9]* Select a File, e.g. sar -u -f /var/log/sysstat/sa17 sar -u -f /var/log/sysstat/sa17 |less Check sar On Remote machines for i in 22 23 24 25; do sar -u -f /var/log/sysstat/sa$i | awk ‘{sum+=$6} END { print sum/NR}’; done
-
Linux – IO Wait Monitoring – Top, IOStat and WMStat
1. Top top -c column wa => io wait 2. IOStat Installation sudo apt-get install -y sysstat iostat -k 3 IO History ls /var/log/sysstat/sa[0-9]* Select a File, e.g. sar -u -f /var/log/sysstat/sa17 3. VMStat vmstat 5 120 Help: vmstat –help Usage: vmstat [options] [delay [count]] Options: -a, –active active/inactive memory -f, –forks number of forks…
-
Unix – Executing Top once or Every X Seconds
Top Every Second -Version 1 top -c -b Top Every Second -Version 2 top -c -b -d 1 Top Every 5 Seconds top -c -b -d 5 Top Only once top -c -b -n 1 top -h procps-ng version 3.3.3 usage: top -hv | -bcHiSs -d delay -n limit -u|U user | -p pid[,pid] -w…
-
Unix – Show, Create and Delete Command Alias
Define an Alias The first example causes ls -l to be executed when the command ll is entered: alias ll ls -l Show all defined Alias alias Show Alias for specific Alias alias ls Alias File – .bash_aliases The alias file located in ~/.bash_aliases is executed on startup. Below is an example of .bash_aliases. cat…