Posts

Es werden Posts vom Mai, 2017 angezeigt.

This and sed

Sed is a nice little tool that is quite hard to understand. While a longer tutorial can be found here . I found it especially useful for editing config files. If you want to deny root login via ssh you can simply enter this command: # sudo sed -ir 's/^(PermitRootLogin) .+/\1 no/' /etc/ssh/sshd_config It uses pattern matching a la perl and s/ searches for a line that ^starts with "PermitRootLogin" followed by one or more other characters. After the second slash we enter how it is replaced and here \1 fills in the bracketed "PermitRootLogin" string and then we add "no". In Perl this would look like this: # sudo perl -pi -e 's/^PermitRootLogin.+/PermitRootLogin no/'  /etc/ssh/sshd_config

Selected lessons in bash scripting

The masterpiece Let us first have a look at a more or less complicated bash script that employs a variety of features needed in bash scripting. The following script reads an input csv file line by line, stores each csv entry into a field in an array and then writes each value into a postgres database. #!/bin/bash # requires "list_of_ids" and "historical_Homer_final.csv" in same dir declare -a TASKIDS=(`awk -F"|" '{printf "%s ",$1}' list_of_ids`) declare -a DESCIDS=(`awk -F"|" '{printf "%s ",$2}' list_of_ids`) while read line do IFS=',' read -r -a array Arrays We can declare an array by using declare -a followed by the variable and assign operator and then the respective list of white space separated values. Another way to declare an array is in the line IFS=',' read -r -a array <<< "$line" . Here we use the comma field separator and the read command in order to re...