Skip to main content

makefileMaker.sh

0 likes • Mar 7, 2021 • 1 view
Shell
Loading...

More Shell Posts

Bash Basics

0 likes • Nov 19, 2022 • 1 view
Shell
name="John"
echo ${name}
echo ${name/J/j} #=> "john" (substitution)
echo ${name:0:2} #=> "Jo" (slicing)
echo ${name::2} #=> "Jo" (slicing)
echo ${name::-1} #=> "Joh" (slicing)
echo ${name:(-1)} #=> "n" (slicing from right)
echo ${name:(-2):1} #=> "h" (slicing from right)
echo ${food:-Cake} #=> $food or "Cake"

getDependencies.sh

0 likes • Oct 30, 2020 • 2 views
Shell
#!/bin/bash
#getDependencies.sh by Leif Messinger
grep -Po '#include\s*"\K.+(?=")' | while read -r line ; do
echo -n " $line"
./getDependencies.sh < $line
done

pinger.sh

0 likes • Mar 21, 2021 • 0 views
Shell
#pinger.sh by Leif Messinger
#./pinger.sh [ADDRESS] to search
#./pinger.sh [ADDRESS] & to search in the background
#https://serverfault.com/a/42382
ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded
until ping -c1 "$1" >/dev/null 2>&1; do :; done & # The "&" backgrounds it
trap "kill $!; ping_cancelled=true" SIGINT
wait $! # Wait for the loop to exit, one way or another
trap - SIGINT # Remove the trap, now we're done with it
if [ "$ping_cancelled" == true ] #https://stackoverflow.com/a/21210966/10141528
then
printf "The pinger for $1 just closed bro.\n"
else
printf "$1 IS UP BROOO\a\n"
fi

diskRipper.sh

0 likes • Apr 21, 2021 • 0 views
Shell
#diskRipper.sh by Leif Messinger
#For use on debian, where your cds aren't immediately mounted
wall "CD inserted boss"
set -x #echo on
cdDrivePath=$(ls -l /dev/cdrom | awk '{print $NF}')
#CD could have no label, so that's why I need awk
cdLabel=$(lsblk -n "/dev/$cdDrivePath" -o label)
if [[ ! -z "$cdLabel" ]]; then #CD has label
folderName=$cdLabel
echo "The cd label is ${folderName}"
if mkdir ./cds/"${folderName}"; then #Folder didn't exist before
sudo mount /dev/cdrom ./.cdmountpoint
sudo cp -r ./.cdmountpoint/* "./cds/${folderName}"
sudo chmod -R 777 "./cds/${folderName}"
sudo umount ./.cdmountpoint
eject
wall "CD done and ejecting"
else
wall "Already read that cd, skipped"
fi
else
wall "CD had no label, skipped"
fi

LeetCode #192: Word Frequency

0 likes • Oct 15, 2022 • 42 views
Shell
awk '\
{ for (i=1; i<=NF; i++) { ++D[$i]; } }\
END { for (i in D) { print i, D[i] } }\
' words.txt | sort -nr -k 2

cpcmd.sh

0 likes • Sep 29, 2021 • 19 views
Shell
#!/bin/bash
#cpcmd.sh [file1 [file2...]]
#Prints out the commands needed to copy the file to your local machine
#This will work on any server that also has the same hostname as in your hosts file.
#I should update this to detect if a file is a directory, and enable recursion for those commands. If you do it now, it will probably just warn you.
if [ -n "$1" ]; then
while [ -n "$1" ]; do
printf "scp \"$(whoami)@$(hostname):"
printf `readlink -f $1`
printf "\" .\n"
shift
done
else
echo "scp \"$(whoami)@$(hostname):$PWD/*\" ."
fi
#-----------EDIT:
#On the UNT cell machines, you have to do this script instead
#if [ -n "$1" ]; then
# while [ -n "$1" ]; do
# printf "scp $(whoami)@$(hostname).eng.unt.edu:"
# printf `readlink -f $1`
# printf " .\n"
# shift
# done
#else
# echo "scp $(whoami)@$(hostname).eng.unt.edu:$PWD/* ."
#fi