-
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
Supermicro 6028R-E1CR24N 24x LFF- Wholesale Build Your Own Storage Server
$249.99
Tyan GT86C-B5630 12x 3.5" Storage Server Wholesale Build Your Own Server
$263.99
Dell R640 8x 2.5" SFF Server iDRAC ENT - Wholesale Custom Build Your Server
$269.99
1U Server (6-8 VM's) Vsphere VPS Short Depth 20" XEON 3.5Ghz 32GB RAM X10SLM-F
$135.00
Dell PowerEdge R630 Server 2x E5-2640v3 2.60Ghz 16-Core 64GB H330
$195.00
2U 12 Bay SAS3 SuperMicro Server 6028U-TR4T+ W/ X10DRU-i+ Barebone 12 Caddy RAIL
$199.00
Dell PowerEdge R630 Server 2x E5-2690v3 2.60Ghz 24-Core 128GB H330 Rails
$288.85
Dell PowerEdge R630 Server | 2x Xeon E5-2667v4, 128GB, RAM, H730, Dual 750w PSU
$229.00
Dell PowerEdge R630 10SFF Server 2xIntel E5-2637 V4 32GB 2x120GB SSD H730 2x750W
$249.99
Dell PowerEdge R730XD Server 2x E5-2640 V3 -16 Cores H730 32GB RAM 4x RJ45
$256.99