• Aug 7, 2023 •C S
0 likes • 2 views
# Three ways of checking if a file exists in a shell script FILE=/etc/resolv.conf if test -f "$FILE"; then echo "$FILE exists." fi if [ -f "$FILE" ]; then echo "$FILE exists." fi if [[ -f "$FILE" ]]; then echo "$FILE exists." fi
• Feb 22, 2022 •LeifMessinger
0 likes • 1 view
#Leif Messinger #For when you want to search a lot of words in a file fast #Arg 1 is the argument the list of words you want to search #Arg 2 is the file you want to search #-z means that it looks at the file as a whole, just treating newlines a characters. #-r is regex. Needed for $, even tho the documentation says you don't need it. They are liars. #First command replaces all . with \. and all - with \- #Second command takes all newlines and replaces them with )|( #Third command takes the trailing |( and deletes it #Forth command puts a /( at the start #Fith command puts /!d at the end. This tells it to not delete any lines that match the pattern. #The second sed takes the output of the first sed as a command that searches any of the combined words #-f - takes a command from the input sed -z -r -e 's/\./\\\./g ; s/\-/\\\-/g' -e 's/\n/\)\|\(/g' -e 's/\|\($//' -e 'i/\(' -e 'a/!d' $1 | sed -r -f - $2
• Sep 23, 2024 •AustinLeath
0 likes • 6 views
CLIENT_VPN_ID="cvpn-endpoint-xxxxxxxxxxxx" for region in $(aws ec2 describe-regions --query "Regions[].RegionName" --output text); do echo "Searching in region: $region" aws ec2 describe-client-vpn-endpoints --region $region --query "ClientVpnEndpoints[?ClientVpnEndpointId=='$CLIENT_VPN_ID']" --output table done
• Sep 30, 2021 •LeifMessinger
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
• May 13, 2023 •LeifMessinger
#!/bin/bash # Turns 4 spaces into tabs. # Mostly stolen from AI # Define the directory to process DIRECTORY=$1 TabCount=${2:-'4'} #Defaults to 4 # Check if directory is specified if [ -z "$DIRECTORY" ]; then echo "Error: Directory not specified." exit 1 fi # Check if directory exists if [ ! -d "$DIRECTORY" ]; then echo "Error: Directory does not exist." exit 1 fi # Find all files in directory and subdirectories FILES=$(find "$DIRECTORY" -type f) # Loop through each file and unexpand it for FILE in $FILES; do unexpand -t "$TabCount" "$FILE" > "$FILE.tmp" mv "$FILE.tmp" "$FILE" done echo "Done!"
• Nov 18, 2022 •AustinLeath
# # Austin Leath # checks for /Desktop symlink. Creates the symlink if it doesnt already exist # #Fetch the target user if desired, otherwise use the currently logged in user. if [ "$4" != "" ]; then TARGET_USER=$4 else TARGET_USER=$3 fi if [ "$5" != "" ]; then DIRECTORY_NAME=$5 else TARGET_USER="$3 Desktop" fi # Functions CHECK_SYMLINK() { if test -f "/Desktop"; then echo "/Desktop exists" else echo "/Desktop does not exist" fi } CHECK_SYNTHETIC_CONF() { if test -f "/etc/synthetic.conf"; then echo "/etc/synthetic.conf exists" else echo "/etc/synthetic.conf does not exist" fi } CREATE_SYMLINK() { if [[ $(CHECK_SYNTHETIC_CONF) != "/etc/synthetic.conf exists" ]]; then echo "/etc/synthetic.conf does not exist. creating.." touch /etc/synthetic.conf chown -R root:wheel /etc/synthetic.conf fi if grep -q "$DIRECTORY_NAME" /etc/synthetic.conf; then echo "$DIRECTORY_NAME already exists" exit 1 else echo "$DIRECTORY_NAME\t/Users/$TARGET_USER/Desktop" >> /etc/synthetic.conf fi echo "/Desktop symbolic link created" } if [[ $(CHECK_SYMLINK) != "/Desktop exists" ]]; then CREATE_SYMLINK fi exit 0