Results 1 to 4 of 4

Thread: Some Useful Bourne shell functions for Knoppix

  1. #1
    Senior Member registered user
    Join Date
    May 2006
    Location
    Columbia, Maryland USA
    Posts
    1,631

    Some Useful Bourne shell functions for Knoppix

    .
    Using /etc/profile to organize small bash scripts in Knoppix

    I've gathered a few small bash code snippets over time which I find occasionally useful.
    In addition, I've found it convenient to add these as individual functions to /etc/profile.
    This makes it easy to carry forward this material from one version of Knoppix to the next.
    I haven't seen this idea per se any place else. Since it seems to work for me without any
    hitch, I thought I'd put it out here for others to try.***

    I've expounded elsewhere on this forum on most if not all of the specific examples shown
    here, so I won't volunteer defense of them here, but I'd be happy to discuss any of them.
    I'd be more interested in learning new, similar short scripts others might have found useful,
    and of course, any constructive comments on using /etc/profile in this way.

    Code:
    # Beginning of /etc/profile additions for Knoppix.
    # These snippets to be appended to /etc/profile, retaining its root:root permissions.
    Count() { # Count wifi disconnects since boot (requires syslog)
    echo -e 'Time now:       \c'; date '+%H:%M:%S' 
    echo -e 'Time at start:  \c'; less /var/log/syslog | grep restart | awk -F' ' '{ print $3 }' 
    echo -e 'Number of Disconnects: \c'; less /var/log/syslog | grep -c disconnecting 
    }
    
    Channel() { # Assess strengths of those on wifi Channel $1
    sudo iwlist wlan0 scan | grep -e Freq -A 3 |
    grep "(Channel $1)" -A 3 | grep -v key 
    }
    
    Uncommon.dpkg() { # define packages uncommon between dpkg.current & dpkg.$1
    dpkg --get-selections > /tmp/dpkg.current
    comm -3 --nocheck-order /tmp/dpkg.current "dpkg.$1" | less | tee uncommon
    }
    
    MakeOverlay() { # Cloop-compress & save /KNOPPIX-DATA as /mnt-system/KNOPPIX$1
    ISO=KNOPPIX$1; ISODIR=/mnt-system/; ISOSRC=KNOPPIX-DATA
    echo -e "Creating "$ISO"; patience, this may take some time..."
    cd /; sudo mkisofs -x *gvfs* -x *[Cc]ache* -iso-level 4 -R -U \
    $ISOSRC | create_compressed_fs -B 131072 -m - - > $ISODIR$ISO
    echo ".done; "$ISO" additions from $ISOSRC saved to "$ISODIR"."
    }
    
    SaveConfig() { # Save tar.gz-ed collections of config files at /mnt-system/
    cd /; KEEP=/mnt-system/update$(date +"%m%d%H").tar.gz
    echo -e "Creating "$KEEP"; patience..\c"; tar cfz $KEEP \
    home/knoppix/.config  home/knoppix/.mozilla  mnt-system/boot/syslinux/*.cfg \
    etc/X11/Xsession.d/45*  etc/rc.local  etc/syslog-knoppix.conf  etc/profile
    echo ".done."
    }
    
    RestoreConfig() { # Given PEEK's date as $1, in %m%d%H format, restore $PEEK to $2 
    PEEK="/mnt-system/update$1.tar.gz"
    dialog --yesno "Restoring "$PEEK" to "$2"; is this correct?" 6 45
    if [ $? -eq 0 ]
        then echo -e "Restoring "$PEEK" files to "$2"..\c"
             tar -xf $PEEK -C $2
             echo ".done."
        else echo "Aborting."
    fi
    }
    # Copyright 2014 by TJ Hoye, License GPL Version 2
    # End of /etc/profile additions for Knoppix.
    ***I've recently discovered two useful things.
    1. There's a general precedence for this at:
    http://www.linuxfromscratch.org/blfs...s/profile.html
    2. Modifiying /etc/profile exactly this way will crash Mint16 Xfce LiveUSBs.
    Some work-around will have to be developed if one were to use this idea there;
    a logical candidate there might be .profile in /home/mint, but I haven't tried that.

  2. #2
    Senior Member registered user
    Join Date
    May 2006
    Location
    Columbia, Maryland USA
    Posts
    1,631

    An update on utilities for Knoppix LiveUSBs

    .
    Greetings, Knoppix forum members & guests.

    Attached please find a newer version of utilities for Knoppix.
    I have found this notion of arranging a number of small utilities
    as functions of /etc/profile very workable and have both tweaked
    the older functions and added a few new ones. I have also decided
    that /home/knoppix/.bashrc is probably a more traditional location
    for such functions.

    In writing up notes on this new edition it has become obvious even
    to me that these particular utilities are rather idiosyncratic,
    and very much tailored to my own exact needs and preferences.
    Even so, I sincerely hope you may find the ideas useful even if
    the details need that you provide your own adaptation(s) to your
    own specific needs and preferences.

    Code:
    # Beginning of .bashrc utilities for Knoppix LiveUSBs.
    #
    # Note 1:  Save this file as /home/knoppix/.bashrc with its ownership also
    # chown knoppix:knoppix and make .bashrc executable with chmod +x .bashrc.
    #
    # Note 2:  From a Knoppix LiveCD or an un-modified LiveUSB, prepare
    # and save a reference dpkg.$1 as follows:
    # dpkg --get-selections > /home/knoppix/dpkg.73CD (or dpkg.73USB).
    #
    # Note 3:  Several utilities require re-establishment of /var/log/syslog.
    # To re-establish syslog in Knoppix, revise /etc/syslog-knoppix.conf; 
    # just below its existing tty12 statement, add the following:
    # *.*;auth,authpriv.none [2 tabs] /var/log/syslog
    #
    # Note 4:  Many of these utilities  work generally well with most Linux 
    # distributions, but Update and Overlay utilities are uniquely applicable to 
    # Knoppix LiveUSB implementations because of Knoppix's unique architecture.
    #
    # Note 5:  The date alias utility extremely idiosyncratic to Windows set-up,
    # Eastern US location, tzdata, Knoppix treatment of 'localtime' and my own
    # personal preference for desktop time presentation.  
    #
    # Note 6:  Uncommon utility results make the most sense as a summary of
    # packages added since a LiveUSB was first prepared, if a) packages are
    # only added, never 'removed'; and b) synaptic or apt is never reloaded.
    #
    # Note 7:  My wifi is at wlan0; YMMV. 
    #
    
    alias 'grep=grep -i --color'
    alias "date=date | sed 's/UTC/EDT/'"
    alias 'Syslog=less /var/log/syslog'
    
    at.Start(){ # echo time at Start (requires Syslog)
    echo -e "at  Start:  \c"; Syslog | grep restart | awk '{ print $3 }'
    }
    
    Boot.Time(){ # Seconds to browser on-line (requires Syslog)
    echo -e "Online at:  \c"; Syslog | grep avahi   | awk '{ print $3 }' 
    at.Start
    }
    
    Disconnects() { # Wifi disconnects since boot (requires Syslog)
    echo -e "Time now:   \c"; date | awk '{ print $4 }' 
    at.Start
    echo -e "Wifi disconnects:  \c"; Syslog | grep -c disconnecting
    }
    
    Channel() { # Assess strengths of those on wifi Channel $1
    sudo iwlist wlan0 scan | grep -e Freq -A 3 |
    grep "(Channel $1)" -A 3 | grep -v key | grep -v Freq
    }
    
    Channels() { # Assess strengths of those on wifi Channels 1 to 11
    sudo iwlist wlan0 scan | grep -e Freq -A 3 | grep -v key > scanlist
    for i in 1 2 3 4 5 6 7 8 9 10 11; do
    echo ".......................Channel "$i"........................."
    less scanlist | grep "(Channel $i)" -A 3 | grep -v Freq; done
    }
    
    Uncommon.dpkg() { # List packages uncommon to dpkg.current & "dpkg.$1"
    dpkg --get-selections > /tmp/dpkg.current
    comm -3 --nocheck-order /tmp/dpkg.current "dpkg.$1" | less | tee uncommon
    }
    
    MakeOverlay() { # Cloop-compress & save /KNOPPIX-DATA as /mnt-system/KNOPPIX$1
    ISO=KNOPPIX$1; ISODIR=/mnt-system/; ISOSRC=KNOPPIX-DATA
    echo -e "Creating "$ISO"; patience, this may take some time..."
    cd /; sudo mkisofs -x *[Cc]ache* -R -U \
    $ISOSRC | create_compressed_fs -B 131072 -m - - > $ISODIR$ISO
    echo ".done; "$ISO" additions from $ISOSRC saved to "$ISODIR"."
    }
    
    MakeUpdate() { # Save tar.gz-ed collections of own files at /mnt-system/
    cd /; KEEP=/mnt-system/update$(date +"%m%d%H").tar.gz
    echo -e "Creating "$KEEP"; patience..\c"
    tar -cz --exclude=*.gvfs* --exclude=*[Cc]ache* --exclude=*Downloads* \
    -f $KEEP home/knoppix  etc/xdg/lxsession/LXDE/autostart          \
    etc/rc.local  etc/X11/Xsession.d/45* etc/syslog-knoppix.conf \
    mnt-system/boot/syslinux/syslinux.cfg; echo ".done."
    }
    
    RestoreUpdate() { # Given KEEP's date as $1, in %m%d%H format, restore $KEEP to $2 
    KEEP="/mnt-system/update$1.tar.gz"
    dialog --defaultno --yesno "Restoring "$KEEP" to "$2"; is this correct?" 6 45
    if [ $? -eq 0 ]
        then echo -e "Restoring "$KEEP" files to "$2"..\c"
             tar -xf $KEEP -C $2; echo ".done."
        else echo "Aborting."
    fi
    }
    
    IsoToDev() { # Expand Iso $1 onto Dev $2 
    ISO=$1; DEV=$2
    dialog --defaultno --yesno "Expand "$ISO" onto "$DEV"; is this correct?" 6 45
    if [ $? -eq 0 ]
        then echo -e "Expanding "$ISO" files onto "$DEV"..\c"
        # sudo dd if=$ISO of=$DEV bs=8M && sync  # still under development
        else echo "Aborting."
    fi
    }
    
    #
    # Copyright 2014 by TJ Hoye, License GPL Version 2
    #
    # End of .bashrc utilities for Knoppix LiveUSBs.

  3. #3
    Senior Member registered user
    Join Date
    May 2006
    Location
    Columbia, Maryland USA
    Posts
    1,631

    Oops.

    .
    In revising MakeUpdate slightly, I've found an error that needs correcting as well.
    The revision is to make the time stamp %y%m%d rather thant %m%d%H. The error is
    in not remembering that I had commandeered MY date command from its usual definition.
    Thus, we need HERE to use \date instead of date in the MakeUpdate function.

    Code:
    MakeUpdate() { # Save tar.gz-ed collections of own files at /mnt-system/
    cd /; KEEP=/mnt-system/update$(\date +"%y%m%d").tar.gz
    echo -e "Creating "$KEEP"; patience..\c"
    tar -cz --exclude=*.gvfs* --exclude=*[Cc]ache* --exclude=*Downloads* \
    -f $KEEP home/knoppix  etc/xdg/lxsession/LXDE/autostart          \
    etc/rc.local  etc/X11/Xsession.d/45* etc/syslog-knoppix.conf \
    mnt-system/boot/syslinux/syslinux.cfg; echo ".done."
    }
    
    RestoreUpdate() { # Given KEEP's date as $1, in %y%m%d format, restore $KEEP to $2 
    KEEP="/mnt-system/update$1.tar.gz"
    dialog --defaultno --yesno "Restoring "$KEEP" to "$2"; is this correct?" 6 45
    if [ $? -eq 0 ]
        then echo -e "Restoring "$KEEP" files to "$2"..\c"
             tar -xf $KEEP -C $2; echo ".done."
        else echo "Aborting."
    fi

  4. #4
    Senior Member registered user
    Join Date
    May 2006
    Location
    Columbia, Maryland USA
    Posts
    1,631

    Bash utilities for Knoppix 7.4

    .
    The purpose of this posting is to update a previous similar offering
    of bash utilites for Knoppix 7.2. There are several ideas I hope you
    may find useful:
    1. The use of .bashrc to organize useful small utilities & aliases;
    2. Utilities to create & restore an update function, update*.tar.gz;
    3. A utility to convert read/write persistence files to compact
    read-only cloop equivalents; and
    4. Utilities with which to assess the immediate wifi environment.

    Code:
    # Beginning of .bashrc utilities for Knoppix 7.4 LiveUSBs.      8/29/14
    #
    # Note 1:  Save this file as /home/knoppix/.bashrc with its ownership also
    # chown knoppix:knoppix and make .bashrc executable with chmod +x .bashrc.
    #
    # Note 2:  Several utilities require re-establishment of /var/log/syslog.
    # To re-establish syslog in Knoppix 7.4, move /etc/syslog-knoppix.conf; 
    # to /etc/syslog-knoppix.conf.orig, and 
    # do ln -s  /etc/sbin/rsyslogd /sbin/syslogd
    #
    # Note 3:  My wifi is at wlan0; YMMV. 
    #
    alias 'grep=grep -i --color'
    alias 'df=df -kTh'
    alias 'wifi.card=lspci -vnn -d 14e4:'     # Broadcom specific
    alias 'Syslog=sudo less /var/log/syslog'  # requires syslog
    
    at.Start(){ # echo time at Start (requires Syslog)
    echo -e "at Start:   \c"; Syslog | grep 'acpid: start' | awk '{ print $3 }'
    }
    
    Disconnects() { # Wifi disconnects since boot (requires Syslog)
    echo -e "Time now:   \c"; date | awk '{ print $4 }' 
    at.Start; echo -e "Wifi disconnects:  \c"; Syslog | grep -c disconnecting
    }
    
    Channel() { # Assess strengths of those on wifi Channel $1
    sudo iwlist wlan0 scan | grep -e Freq -A 3 |
    grep "(Channel $1)" -A 3 | grep -v key | grep -v Freq
    }
    
    Channels() { # Assess strengths of those on wifi Channels 1 to 11
    sudo iwlist wlan0 scan | grep -e Freq -A 3 | grep -v key > scanlist
    for i in 1 2 3 4 5 6 7 8 9 10 11; do
    echo ".......................Channel "$i"........................."
    less scanlist | grep "(Channel $i)" -A 3 | grep -v Freq; done
    }
    
    MakeOverlay() { # Cloop-compress & save /KNOPPIX-DATA as /mnt-system/KNOPPIX$1
    ISO=KNOPPIX$1; ISODIR=/mnt-system/; ISOSRC=KNOPPIX-DATA
    echo -e "Creating "$ISO"; patience, this may take some time..."
    cd /; sudo mkisofs -x *[Cc]ache -R -U \
    $ISOSRC | create_compressed_fs -B 131072 -m - - > $ISODIR$ISO
    echo ".done; "$ISO" additions from $ISOSRC saved to "$ISODIR"."
    }
    
    MakeUpdate() { # Save tar.gz-ed collections of own files at /mnt-system/
    cd /; KEEP=/mnt-system/update$(date +"%y%m%d").tar.gz
    echo -e "Creating "$KEEP"; patience..\c"; 
    tar -cz --exclude=*[Cc]ache --exclude=*chro \
    -f $KEEP home/knoppix/.mozilla  home/knoppix/.config  home/knoppix/.bashrc  \
    etc/rc.local  etc/X11/Xsession.d/45*  mnt-system/boot/syslinux/syslinux.cfg \
    echo ".done."
    }
    
    RestoreUpdate() { # Given KEEP's date as $1, in %y%m%d format, restore $KEEP to $2 
    KEEP="/mnt-system/update$1.tar.gz"
    dialog --defaultno --yesno "Restoring "$KEEP" to "$2"; is this correct?" 6 45
    if [ $? -eq 0 ]
        then echo -e "Restoring "$KEEP" files to "$2"..\c"
             tar -xf $KEEP -C $2; echo ".done."
        else echo "Aborting."
    fi
    }
    
    #
    # Copyright 2014 by TJ Hoye, License GPL Version 2
    #
    # End of .bashrc utilities for Knoppix 7.4 LiveUSBs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


HP RGB G3 Desktop Computer i7 32GB 2TB SSD 2TB HDD New 24

HP RGB G3 Desktop Computer i7 32GB 2TB SSD 2TB HDD New 24" LED Built-in WiFi Pro

$164.99



Custom RGB Gaming Desktop PC Intel Core i7 3.40 Quad 32 GB SSD Nvidia RTX 3060 picture

Custom RGB Gaming Desktop PC Intel Core i7 3.40 Quad 32 GB SSD Nvidia RTX 3060

$544.00



SGIN 17.3

SGIN 17.3" Laptop 8GB RAM 256GB SSD Celeron Quad-Core Up to 2.6GHz HD 1080P

$225.00



New HP 24

New HP 24" Touchscreen All In One Computer i3-1115G4 Up To 32GB & 2TB SSD Win 11

$389.99



Intel Xeon E5-2667 V2 LGA 2011 3.3GHz 8 Core 130W 25MB 8GT/s CPU Processor picture

Intel Xeon E5-2667 V2 LGA 2011 3.3GHz 8 Core 130W 25MB 8GT/s CPU Processor

$11.99



AMD Ryzen 7 7800X3D - Ryzen 7 7000 Series 8-Core Socket AM5 120W CPU Processor picture

AMD Ryzen 7 7800X3D - Ryzen 7 7000 Series 8-Core Socket AM5 120W CPU Processor

$488.99



AMD Ryzen 7 5700X3D 8-Core 16-Thread 4.1GHz Socket AM4 CPU picture

AMD Ryzen 7 5700X3D 8-Core 16-Thread 4.1GHz Socket AM4 CPU

$194.99



Lenovo ThinkPad P1 Gen 3 - Core i9, 10885H @2.4GHz, 32GB RAM, 1TB SSD, Win11 Pro picture

Lenovo ThinkPad P1 Gen 3 - Core i9, 10885H @2.4GHz, 32GB RAM, 1TB SSD, Win11 Pro

$160.00



RGB Gaming Desktop Computer i7 PC 32GB RAM 2TB SSD GTX 3050 W11P Custom Build picture

RGB Gaming Desktop Computer i7 PC 32GB RAM 2TB SSD GTX 3050 W11P Custom Build

$499.99



HP Z8 G4 Workstation 36 Core 2x Gold 6154 64GB RAM No HDD/ GPU/ OS picture

HP Z8 G4 Workstation 36 Core 2x Gold 6154 64GB RAM No HDD/ GPU/ OS

$850.95