-
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
Cisco UCS LSI MegaRAID 9271CV-8I SAS2308 PCIe SAS Internal RAID Controller
$28.00
ACASIS 2.5/3.5 inch 2 Bay SATA USB 3.0 Hard Drive Disk HDD SSD Enclosure 4 RAID
$58.99
Intel PCIe SSD AIC RAID Controller Card G97168-252
$44.55
Oracle 7085209 LSI MegaRAID SAS 9361-8i 1GB Cache 12Gbps SAS/SATA PCIe RAID Card
$28.20
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
$39.95
LSI MegaRAID 9361-8i 12Gbps PCIe 3 x8 SATA SAS 3 8 Port RAID + BBU & CacheVault
$39.00
ORICO Multi Bay RAID Hard Drive Enclosure USB 3.0/ Type-C For 2.5/3.5'' HDD SSDs
$82.49
4 Bay RAID External Hard Drive Enclosure for 2.5/3.5" SATA HDD/SSD
$79.99
G-Technology G-SPEED eS PRO 4-Bay Mini-SAS RAID Array 0G02057
$99.99