Friday, March 20, 2020

shell if statement



reference: https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php

if [ <some test> ]
then
<commands>
fi

================== compare number ================
#!/bin/bash
# Basic if statement
if [ $1 -gt 100 ]
then
    echo Hey that\'s a large number.
    pwd
fi
================== compare string ================
#!/bin/sh
if [ -z $1 ]
then
   echo "no input string given"
   return
fi
==============================================




  • Operator Description
    ! EXPRESSION The EXPRESSION is false.
    -n STRING The length of STRING is greater than zero.
    -z STRING The lengh of STRING is zero (ie it is empty).
    STRING1 = STRING2 STRING1 is equal to STRING2
    STRING1 != STRING2 STRING1 is not equal to STRING2
    INTEGER1 -eq INTEGER2 INTEGER1 is numerically equal to INTEGER2
    INTEGER1 -gt INTEGER2 INTEGER1 is numerically greater than INTEGER2
    INTEGER1 -lt INTEGER2 INTEGER1 is numerically less than INTEGER2
    -d FILE FILE exists and is a directory.
    -e FILE FILE exists.
    -r FILE FILE exists and the read permission is granted.
    -s FILE FILE exists and it's size is greater than zero (ie. it is not empty).
    -w FILE FILE exists and the write permission is granted.
    -x FILE FILE exists and the execute permission is granted.



  • = is slightly different to -eq. [ 001 = 1 ] will return false as = does a string comparison (ie. character for character the same) whereas -eq does a numerical comparison meaning [ 001 -eq 1 ] will return true.
  • When we refer to FILE above we are actually meaning a path. Remember that a path may be absolute or relative and may refer to a file or a directory.



  • bash> test 001 = 1
  • bash> echo $?
  • bash> 1
  • bash> test 001 -eq 1
  • bash> echo $?
  • bash> 0
  • bash> touch myfile
  • bash> test -s myfile
  • bash> echo $?
  • bash> 1
  • bash> ls /etc > myfile
  • bash> test -s myfile
  • bash> echo $?
  • bash> 0
  • Tuesday, February 11, 2020

    How to configure routing between LAN and WAN



    https://monoinfinito.wordpress.com/series/setting-up-a-linux-gatewayrouter-a-guide-for-non-network-admins/

    Monday, February 10, 2020

    dhcp perf tools


    1. How to install
        kea-admin contains perfdhcp binary

    $ sudo apt install kea-admin

    $ sudo perfdhcp -p 60 -r 100 -d 5 -R 50 192.168.1.1

    2. User manual
    https://users.isc.org/~tomasz/perfdhcp/dhcp-perf-guide.html#perfdhcp-commandline-examples
    - adding delayed-ack 32 that allows packets to queue before send
    - max-ack-delay that increase time to fsync
    - ping-check false
    - dont-use-fsync to true

    3. Build your own
        build/install from source

    $ sudo apt -y install automake libtool pkg-config build-essential ccache

    $ sudo apt -y install libboost-dev libboost-system-dev liblog4cplus-dev libssl-dev

    $ git clone https://gitlab.isc.org/isc-projects/kea.git

    $ cd kea

    $ autoreconf --install

    $ ./configure [your additional options here]

    $ make -j4

    $ sudo make install

    $ echo "/usr/local/lib/hooks" > /etc/ld.so.conf.d/kea.conf

    $ ldconfig

    Wednesday, February 5, 2020

    git submodule



    *** sync submodule
    $ git checkout master
    M meta-openembedded
    M poky
    $ git submodule update

    git submodule add https://git.kernel.org/pub/scm/linux/kernel src/linux

    git config examples)
    .git/config
    [submodule "linux"]
    url = https://git.kernel.org/pub/scm/linux/kernel

    .gitmodules
    [submodule "linux-msm"]
    path = src/linux
    url = https://git.kernel.org/pub/scm/linux/kernel
    rev = b27efee486f8a24682f36908fb2693a7b310303b

    git clone --recurse-submodules --branch <branch name> <git url>

    git clone --single-branch --recurse-submodules --branch <branch name> <git url>

    git submodule sync
        Synchronizing submodule url for 'xxx'
        fatal: no submodule mapping found in .gitmodules for path 'yyy'
    git rm -r yyy --cached

    trouble shootings)
    git rm --cached src/linux
    rm -rf src/linux
    rm -rf .git/modules/src/linux



    git submodule [--quiet] add [-b branch] [-f|--force]
          [--reference <repository>] [--] <repository> [<path>]
    git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…​]
    git submodule [--quiet] init [--] [<path>…​]
    git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase]
          [--reference <repository>] [--merge] [--recursive] [--] [<path>…​]
    git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>…​]
    git submodule [--quiet] foreach [--recursive] <command>
    git submodule [--quiet] sync [--] [<path>…​]


    *** Update git submodule to their remote origin

    # Get the submodule initially
    git submodule add ssh://bla submodule_dir
    git submodule init

    # Time passes, submodule upstream is updated
    # and you now want to update

    # Change to the submodule directory
    cd submodule_dir

    # Checkout desired branch
    git checkout master

    # Update
    git pull

    # Get back to your project root
    cd ..

    # Now the submodules are in the state you want, so
    git commit -am "Pulled down update to submodule_dir"


    git submodule foreach git pull origin master





    Thursday, January 23, 2020

    Tuesday, January 14, 2020

    apt clean



    sudo rm /var/lib/apt/lists/*
    sudo rm /var/cache/apt/*.bin
    
    
    sudo apt update

    Monday, January 13, 2020

    VirtualBox clone / resize



    /Users/peteroh/VirtualBox VMs/Ubuntu-16.04/Ubuntu-16.04.vdi

    VBoxManage clonehd Ubuntu-16.04.vdi Ubuntu-16.04-2.vdi --format VDI --variant Standard

    VBoxManage modifyhd Ubuntu-16.04.vdi --resize 50000