Category: OS
-
Unix – Extract File Extension and Filename from Filepath
#file extension for f in *; do fn=”${f%.*}”;echo “fn=$fn,f=$f”; done;
-
Unix – tolower in bash, awk and sed
tr ‘[A-Z]’ ‘[a-z]’ # to lower case sed ‘s/]]/]/g’ # replace ]] with ] awk ‘{print tolower($0)}’ # change whole string to lower sed ‘s/^[0-9]*//g’ # replace all numbers with nothing
-
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…