-
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
USB Flash Drive Memory Stick Pendrive Thumb Drive 4GB, 8GB, 32GB, 64GB 128GB LOT
$249.37
1TB/2TB USB 3.0 Flash Drive Thumb U Disk Memory Stick Pen PC Laptop Storage lot
$80.39
Sandisk 16GB 32GB 64GB 128GB Cruzer Blade Flash Drive Memory Stick USB Lot Pack
$138.90
SanDisk Cruzer Glide USB 3.0 16GB 32GB 64GB 128GB 256GB Flash Drive Memory Lot
$276.48
New TESLA OEM Model S,3,X,Y USB Flash Drive for Dashcam & Sentry Mode 128GB
$18.99
2TB USB 3.0 Flash Drive Memory Photo Stick for iPhone Android iPad Type C 3 IN1
$16.72
64GB USB 3.0 Flash Drive USB Memory Stick High Speed Retractable USB Thumb Drive
$6.99
1TB 2TB Type C USB 3.0 Flash Drive Thumb Drive Memory Stick for PC Laptop New
$9.99
Lot USB Flash Drive Memory Stick Pendrive Thumb Drive 2GB,4GB, 8G, 32G, 64G 128G
$217.13
2TB USB 3.0 Flash Drive Thumb U Disk Memory Stick lot Pen PC Laptop Storage New
$80.39