Search This Blog

Wednesday, October 23, 2019

Update remote /etc/hosts file using sudo

Sudo example

printf 'IP\tHost\n' | ssh -q host "sudo su - root -c 'cat - >> /etc/hosts'"

Wednesday, August 28, 2019

Debug bash scripts


Place the below lines near the top of the script.
Call debuggerIt in the script from a point where debugging should take place or at the start of the script execution.


OUTBASE="/tmp/${USER}/${0##*/}.log"

#-------------------------------------------
debuggerIt()
{
        test -d ${OUTBASE} || mkdir -p ${OUTBASE}
        exec 5> ${OUTBASE}/${0##*/}.debug
        BASH_XTRACEFD="5"
        PS4='$LINENO: '
        set -x
}
#-------------------------------------------
.
more functions
.
.
start of execution.
debuggerIt
more commands

Thursday, April 25, 2019

Remote tar

Copy a files from remote location using a file list.


ssh host "cat fileList | xargs tar cf -" | tar xvf -