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 <<< "$line" ORIGINALDATE=`date --universal '+%s' -d "${array[0]}"` let ORIGINALDATE+=341712000 for index in ${!array[*]} do if [[ $index -ge 1 && ${TASKIDS[$index-1]} -ge 1 ]] then #write value to DB VALUE="${array[$index]}" TASKID=${TASKIDS[$index-1]} DESCID=${DESCIDS[$in