From time to time, my bash scripts turn out to be useful to more than just me.
It doesn’t happen very often, but on the chance that it does, I’m archiving them here.
At Lancaster University, we use Moodle for our Virtual Learning Environment, which is fine most of the time, but a bit of a pain for marking.
This is doubly so, in the case of code submissions, where Moodle will quite happily mangle file names breaking any linkage used in the code.
To reverse Moodle’s mangling, I wrote this quick bash script, which not only creates a folder tree in the form /student/submission-id/…files… but will also unzip any submitted archives in to the correct folder in said tree.
If there are any other Moodle
sufferers users out there who find this useful and extend it in any way, I will gladly merge their edits for the greater good!
for filename in ./*
IFS=‘_’ read -a parts <<< "$filename"
mkdir -p "$user–$index"
if [ "$extension" = "zip" ]; then
unzip "$filename" -d "$user–$index/"
mv "$filename" "$user–$index/$submission"
Download link: demoodle.sh
Random Radio Station
Pull a random radio station from my stream list (used in my radio projects) and play it in console-mode vlc. Try net radio channel hopping, and a new station is only a ctrl+c, up, enter away!
Using Tree To Find The Minimum Power Of Two Larger The File Will Fit To
Used as part of a study in determining the average file size found on the modern Linux/UNIX/BSD system.
If you use this script, I would love to have your filesizes.csv output for /home (or equivalent) so I can use it in my research! No personal data is saved by this script, it just uses ‘tree’ to walk the file system and report sizes.
Because of the length of this file (it’s moderately long) the script can be viewed here: filesize.sh
Generate a Word List from Google’s nGram Lists
This code is terrible, don’t use it (especially if you don’t have much RAM!) – I only put this up for the craziness of it all.
Generate a Quoted, Comma Separated String From a Word List
Note, this assumes that output.txt is blank or non-existent.
PulseAudio Control Wrapper
Save in an executable file as “/usr/local/bin/pavol”, then call “pavol up/down/mute” to control PulseAudio from the terminal – I’m using this for my media key hooks
case "$1" in
/usr/bin/pactl set-sink-volume 0 +$VOLUME_STEP%
/usr/bin/pactl set-sink-volume 0 –$VOLUME_STEP10%
/usr/bin/pactl set-sink-mute 0 toggle
MUTED=$(pactl list sinks | grep Mute: | cut -d: -f2)
LEVEL=$(pactl list sinks | grep ‘^[[:space:]]Volume:’ | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e ‘s,.* \([0-9][0-9]*\)%.*,\1,’)
if [ "$MUTED" == " yes" ]; then
notify-send -t 500 -a pavol -i sound "Volume Control" "Muted"
notify-send -t 500 -a pavol -i sound "Volume Control" "Volume: $LEVEL%"