Skip to main content

Bash Basics

Nov 19, 2022CodeCatch
Loading...

More Shell Posts

cppToStdout.sh

Nov 17, 2021LeifMessinger

0 likes • 6 views

#!/bin/bash
#Takes command line arguments and pulls the header files.
#Good for checking if the function you want is in the header or not.
#cppToStdout.sh "time.h"
while [ "$1" != "" ]; do
echo "#include<$1>" | g++ -x c++ -E -
shift
done

List all AWS EC2 Instances in all regions

Jul 29, 2024AustinLeath

0 likes • 7 views

for region in `aws ec2 describe-regions --output text | cut -f4`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --query 'Reservations[*].Instances[*].{Instance:InstanceId,Subnet:SubnetId}' --region $region
done
#This script is to be used with any AWS CLI configured environment, it will list any EC2 instances and their associated subnet network ID's in JSON format

getDependencies.sh

Oct 30, 2020LeifMessinger

0 likes • 2 views

#!/bin/bash
#getDependencies.sh by Leif Messinger
grep -Po '#include\s*"\K.+(?=")' | while read -r line ; do
echo -n " $line"
./getDependencies.sh < $line
done

mitosis.sh

Apr 3, 2025LeifMessinger

0 likes • 4 views

#!/usr/bin/env bash
#Splits a command across a number of CELL machines
user=$(whoami)
if [[ -z $user ]]; then
echo "whoami failed. Exiting..."
exit 1
fi
command="$1"
if [[ -z $command ]]; then
echo "Need to put in a command."
exit 1
fi
shift
array=("$@")
let start=8
let stop=18
for ((i = $start; i <= $stop; i++)); do
extraZero=$(if [[ "$i" -lt 10 ]]; then echo "0"; fi)
domain="CELL${extraZero}${i}-CSE.ENG.UNT.EDU"
let "index = i - start"
echo ${#array[@]}
if [[ ${#array[@]} != 0 ]] && [[ $index -ge ${#array[@]} ]]; then
echo "$index > ${#array[@]}"
break
fi
ssh -o StrictHostKeyChecking=accept-new "${user}@${domain}" -t "$command ${array[$index]}" &
done

watchLogins.sh

Sep 30, 2021LeifMessinger

0 likes • 8 views

touch /tmp/login1.txt /tmp/login2.txt
while [ true ]
do
who | gawk '{ print $1 }' > /tmp/login2.txt
comm -13 /tmp/login1.txt /tmp/login2.txt
#Just a bit easier to read
#diff /tmp/login1.txt /tmp/login2.txt
cat /tmp/login2.txt > /tmp/login1.txt
sleep 1
done

Update Prefixed Dependencies

Oct 9, 2023C S

0 likes • 133 views

# Update all npm packages under the scope defined by the PREFIX variable ("foo").
PREFIX="foo"; npm ls | grep "$PREFIX" | awk -F/ '{print $NF}' | sed 's/@.*//' | xargs -I package npm update @"$PREFIX"/package