-
Senior Member
registered user
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.
-
Senior Member
registered user
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.
-
Senior Member
registered user
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
-
Senior Member
registered user
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
-
Forum Rules
Dell Poweredge R620 2x E5-2670 2.6ghz 16-Cores / 32gb / H710 / 2x Trays / 750w
$134.99
Dell Poweredge R630 2x Xeon E5-2670 v3 2.3ghz 24-Cores 32gb 180GB SSD 495w
$169.99
Dell PowerEdge R630 Server 2x E5-2697v3 2.60Ghz 28-Core 128GB H730P Rails
$278.45
Dell Poweredge R630 Server 2x E5-2620 V4 =16 Cores | S130 | 32GB RAM | 2x trays
$180.99
Dell Poweredge R210 II Server Xeon E3-1230 3.2ghz Quad 16GB No HDD 2x HDD Caddy
$55.00
New Gigabyte 10 bay SFF Server 2x Xeon Gold 6130 Total 32 Core 64GB DDR4 3x PCIe
$319.20
Dell PowerEdge R640 2.5" SFF 10-bay PERC H740P 8GB iDRAC 9 Ent HP 2x750W w/Rails
$445.00
Dell PowerEdge T320 Server 1x Xeon E5-1410 V2 2.8 GHz 24 GB No HDD No OS
$114.95
Dell R640 8x 2.5" SFF Server iDRAC - Wholesale Custom Build Your Server
$427.99
Dell PowerEdge R430 8SFF 1U Server 2x E5-2660 v3 32gb 4x Trays H730 2x 550w
$189.99