Linux

Pure BASH to remove spaces line by line

Blog tags: 

Here is a neat little script I wrote to remove spaces in CSVs recursively line by line using only pure Bash

#!/bin/bash
INPUT_CSV="test.csv"

set IFS=,
set oldIFS = $IFS
readarray -t arry < ${INPUT_CSV}

for i in "${arry[@]}"
do
   :
        res="${i//[^ ]}"
        cnt="${#res}"
        while [ ${cnt} -gt 0 ]; do
                i=${i/, /,}
                cnt=$[$cnt-1]
        done
        echo $i
done

A few notes about CPU load and resource consumption

Blog tags: 

A few observations about looking at TOP that I hear people asking are regarding what does the % mean, and why can I have over 100% when looking at CPU usage.

Well, its sort of simple. Load averages are the average of the load number for a process in a given period of time. A load number is merely a metric that is an average that takes into account CPU usage (or consumed time-slices) by the process. These could be:

Quick script to generate XML for each network interface

Blog tags: 

#!/bin/bash
# @file statistics.sh
# @author Ron Brash (<a href="mailto:[email protected]">[email protected]</a>)
# @date Jan 2017
# @purpose Collect network interface statistics and other information and output
# it in XML format instead of arbitrary formatting
#

PATH_DIR=/sys/class/net
INTF_WILD="e*"

OpenSSH Signing a File and appending to Signing to File + Verification

Blog tags: 

Create the signing keys

openssl req -nodes -x509 -sha256 -newkey rsa:4096 -keyout "signing.key" \
-out "signingKey.crt" -days 365 -subj "/C=NL/ST=QC CA/L=Montreal/O=PacificSimplicity \
/OU=Dev/CN=Dev Signing Key"

Then sign the file with the following command

Reverse SSH Tunnel

Blog tags: 

Recently went to setup a reverse SSH tunnel and had a few issues such as connections not being allowed, or otherwise. There is also a strong gotcha not documented clearly on the Internet, you can only have one connection per port on the intermediary host. If you want more than one host, you need to use multiple ports; sorry this is the way it is.

Before starting, make sure on BOTH hosts, install:

sudo apt-get install -y openssh-server

Quick and Dirty OpenYuma Build, Run and Test

Blog tags: 

Here is my guide for a quickstart instead of reading their documentation:

Install Prerequisites

# sudo apt-get update
# sudo apt-get install -y git autoconf gcc libtool libxml2-dev libssl-dev make libncurses5-dev libssh2-1-dev openssh-server build-essentials git

Reconfigure SSHD

Edit sshd_config and under the line Port 22, add the following two lines

# sudo vi /etc/ssh/sshd_config

# What ports, IPs and protocols we listen for
Port 22
Port 830
Subsystem netconf /usr/sbin/netconf-subsystem --ncxserver-sockname=830@/tmp/ncxserver.sock

Restart SSH with the following command

sudo service ssh restart

Download, build and install OpenYuma

GIT clone, make and install the following - netconfd will run with your current user

# git clone <a href="https://github.com/OpenClovis/OpenYuma.git">https://github.com/OpenClovis/OpenYuma.git</a> openYuma
# cd openYuma
# make
# sudo make install

# sudo cp /etc/yuma/netconfd-sample.conf /etc/yuma/netconfd.conf
# /usr/sbin/netconfd --superuser=`whoami`

Connecting with yangcli

Open a second terminal and run the command:

# yangcli

Something like the following should appear - note the YOURUSERNAME and YOURPASSWORD variables which need to be replaced with something more appropriate

yangcli> connect server=localhost user=YOURUSERNAME password=YOURPASSWORD
val->res is NO_ERR.

yangcli: Starting NETCONF session for rbrash on localhost

NETCONF session established for rbrash on localhost

Client Session Id: 2
Server Session Id: 1

Server Protocol Capabilities
   base:1.0
   candidate:1.0
   confirmed-commit:1.0
   rollback-on-error:1.0
   validate:1.0
   url:1.0
   xpath:1.0
   notification:1.0
   interleave:1.0
   partial-lock:1.0
   with-defaults:1.0
   base:1.1
   validate:1.1
   confirmed-commit:1.1

Server Module Capabilities
   iana-crypt-hash@2014-04-04
      Features:
         crypt-hash-md5
         crypt-hash-sha-256
         crypt-hash-sha-512
   ietf-inet-types@2013-07-15
   ietf-netconf-acm@2012-02-22
   ietf-netconf-monitoring@2010-10-04
   ietf-netconf-partial-lock@2009-10-19
   ietf-netconf-with-defaults@2011-06-01
   ietf-system@2014-08-06
      Features:
         radius
         authentication
         local-users
         radius-authentication
         ntp
         ntp-udp-port
         timezone-name
         dns-udp-tcp-port
   ietf-yang-types@2013-07-15
   nc-notifications@2008-07-14
   notifications@2008-07-14
   yuma-app-common@2012-08-16
   yuma-arp@2012-01-13
   yuma-mysession@2010-05-10
   yuma-ncx@2012-01-13
   yuma-proc@2012-10-10
   yuma-system@2014-11-27
   yuma-time-filter@2011-08-13
   yuma-types@2012-06-01

Server Enterprise Capabilities
   None

Protocol version set to: RFC 6241 (base:1.1)
Default target set to: <candidate>
Save operation mapped to: commit
Default with-defaults behavior: explicit
Additional with-defaults behavior: trim,report-all,report-all-tagged

Checking Server Modules...

Pages

Subscribe to RSS - Linux