Shell Recipes

2021-05-24T16:42:52+02:00

Paste output from two subshells:

paste <(head -1 data.csv | tr ',' '\n' ) <(cat data.csv | grep pattern | tr ',' '\n') | bat 

dos2unix in vim:

:w ++ff=unix

Gnuplot - Plotting data from a pipe

Date conversion gnuplot -p -e “set dgrid3d; splot ‘-’ using 1:3:2 w lines”

./simulacrum | gnuplot -p -e “plot ‘-’ w l”

cat auction_aggregated_curves_germany_austria_201302*.csv | grep -E “,(1),([-]?[0-9]+.[0-9]+),([0-9]+),Sell” | cut -d’,’ -f’1,4,5,6’ | tr ‘,’ ’ ’ | gnuplot -p -e “set yrange [-50:300]; set xdata time; set timefmt ‘%d/%m/%Y’; splot ‘-’ using 1:4:3”

Something that works: cat auction_aggregated_curves_germany_austria_201302.csv | grep -E “,(19),([-]?[0-9]+.[0-9]+),([0-9]+),Sell” | cut -d’,’ -f’1,5,6’ | tr ‘,’ ’ ’ | sed -re ’s/([0-9])/([0-9])/([0-9])/\3\2\1/g’ | gnuplot -p -e “set zrange [-90:500]; set dgrid3d 50,20; splot ‘-’ using 1:3:2 w l”

Dealing with time

http://www.techrepublic.com/blog/opensource/how-to-handle-time-based-data-with-gnuplot/2671

GNU Parallel

Get the numer of cores for each server in a list. parallel –tag –nonall –sshloginfile servers-case.txt ‘cat /proc/cpuinfo | grep processor | wc -l’

The same for uptime. parallel --tag --nonall --sshloginfile servers-my.txt 'uptime'

List intersting things parallel --tag --nonall --sshloginfile tuc-cust-serv.txt 'ps -ef | grep wergj | grep -Ev "(bash)|(sshd)|(ps -ef)|(grep)"'

Useful options Runs a command only once on a server. –nonall Time out option. If the command runs for longer than sec seconds it will get killed. –timeout sec A way to specify max load? What is the correct usage of this? –load N%

Collected calls gen-jobs.sh ./r-wrapper.sh ./run-cir-short.R 914 /dev/null | \ parallel --sshloginfile tuc-cust-serv.txt -j -1 --eta gen-jobs.sh ./r-wrapper.sh ./run-cir-short.R 1670 log/log.txt | \ parallel --sshloginfile tuc-cust-serv.txt -j -1 --eta --timeout 180 gen-jobs.sh ./r-wrapper.sh ./run-ou-short.R 456 log/ou-d002.txt | \ parallel --sshloginfile tuc-cust-serv.txt -j -1 --eta parallel --tag --nonall --sshloginfile tuc-cust-serv.txt 'uptime'

Resources http://www.gnu.org/software/parallel/man.html