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
  •  


LSI 9305-16i SATA SAS 12Gbs RAID Controller PCIe 3.0 x8 IT-Mode 4* 8643 SATA picture

LSI 9305-16i SATA SAS 12Gbs RAID Controller PCIe 3.0 x8 IT-Mode 4* 8643 SATA

$229.99



Dell R630 8SFF 2.1Ghz 16-Core 128GB H730 RAID 10GB RJ-45 NIC 2x750W PSU 8x Trays picture

Dell R630 8SFF 2.1Ghz 16-Core 128GB H730 RAID 10GB RJ-45 NIC 2x750W PSU 8x Trays

$425.04



Lot of 2 -Dell P2R3R PERC H330 Mini Mono 12Gbps SAS Non-raid Controller 0P2R3R picture

Lot of 2 -Dell P2R3R PERC H330 Mini Mono 12Gbps SAS Non-raid Controller 0P2R3R

$35.99



Dell R740XD2 26LFF 3.6Ghz 8-C 128GB H730P MINI RAID 2x10G SFP+ NIC 2x1100W Rails picture

Dell R740XD2 26LFF 3.6Ghz 8-C 128GB H730P MINI RAID 2x10G SFP+ NIC 2x1100W Rails

$2610.08



Inspur LSI 9300-8i Raid Card 12Gbps HBA HDD Controller High Profile IT MODE picture

Inspur LSI 9300-8i Raid Card 12Gbps HBA HDD Controller High Profile IT MODE

$15.98



LSI MegaRAID 9361-8i 12Gb PCIe 8-Port SAS/SATA RAID 1Gb w/BBU/CacheVault/License picture

LSI MegaRAID 9361-8i 12Gb PCIe 8-Port SAS/SATA RAID 1Gb w/BBU/CacheVault/License

$39.95



Cisco UCS-Raid9271CV-8I Cisco LSI MegaRaid SAS Controller picture

Cisco UCS-Raid9271CV-8I Cisco LSI MegaRaid SAS Controller

$19.01



LSI MegaRAID 9361-8i 12Gbps PCIe 3 x8 SATA SAS 3 8 Port RAID + BBU & CacheVault picture

LSI MegaRAID 9361-8i 12Gbps PCIe 3 x8 SATA SAS 3 8 Port RAID + BBU & CacheVault

$39.00



4 Bay RAID External Hard Drive Enclosure for 2.5/3.5

4 Bay RAID External Hard Drive Enclosure for 2.5/3.5" SATA HDD/SSD

$79.99



ORICO Multi Bay RAID Hard Drive Enclosure USB 3.0/ Type-C For 2.5/3.5'' HDD SSDs picture

ORICO Multi Bay RAID Hard Drive Enclosure USB 3.0/ Type-C For 2.5/3.5'' HDD SSDs

$143.99