-
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.
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
HP ProLiant MicroServer Gen8 Intel Xeon E3-12L V2 8GB RAM
$219.95
Supermicro 2U 6028R-E1CR24N 24x LFF- Wholesale Build Your Own Storage Server
$305.99
SuperMicro 2U; 3.10 GHz Xeon E3-1220 v3; 32 GB DDR3; 2x 3TB, 1 TB HD; 120 GB SSD
$249.99
HPE ProLiant MicroServer Gen-8 Intel Xeon E3-1220L@2.30GHz 8GB RAM 2x 1TB HDD
$249.99
HP ProLiant MicroServer HSTNS-5151 AMD N54 Turion 2 No HDD 8GB RAM
$95.00
Supermicro 502-2 Intel Atom CPU 2GB RAM 1U Server w/ 500GB HDD Storage
$60.00
HP ProLiant MicroServer Gen8 -Intel Xeon® E3-1220Lv2/No OS/2x 1TB HDD (Wiped)
$200.00
HP ProLiant MicroServer Gen8 - Intel Xeon E3-1220L V2 8GB RAM - Used
$229.95
2U 12 Bay SAS3 SuperMicro Server 6028U-TR4T+ W/ X10DRU-i+ Barebone 12 Caddy RAIL
$199.00
1U Supermicro Server 17" Depth X10DRD-LTP 2x E5-2650 V4 64GB RAM 2x HD Bays
$175.00