• 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
• 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
• Nov 18, 2022 •AustinLeath
0 likes • 1 view
echo -e ${PATH//:/\\n} | awk '{print length, $0}' | sort -n | cut -f2- -d' '
• Jul 8, 2024 •C S
0 likes • 17 views
#!/bin/bash # Set the directory to search DIRECTORY="src" # Set the output file OUTPUT_FILE="testids.txt" # Clear the output file > "$OUTPUT_FILE" # Find all .tsx files in the specified directory and its subdirectories find "$DIRECTORY" -type f -name "*.tsx" | while read -r FILE do # Search for instances of 'data-testid="testid"' and append them to the output file grep -o 'data-testid="[^"]*"' "$FILE" >> "$OUTPUT_FILE" # Search for instances of "'data-testid': 'testid'" and append them to the output file grep -o "'data-testid': '[^']*'" "$FILE" >> "$OUTPUT_FILE" done echo "Search complete. Test IDs written to $OUTPUT_FILE."
• Apr 3, 2025 •LeifMessinger
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
• Dec 23, 2024 •AustinLeath
0 likes • 27 views
#!/bin/bash # RCLONE BACKUP SCRIPT (using ionice) # Type crontab -e and copy the line below without the # # 0 0 * * * ionice -c 3 /home/owner/backup.sh >/dev/null 2>&1 nowdate=$(date -u) # OPTIONS WEBHOOK="YOUR_DISCORD_WEBHOOK_LINK_HERE" LOGFILE="/root/backup.log" FROM="/path/where/you/backup/from" TO="backblaze:BucketName/FolderName" SERVERNAME="Server Name" echo "$SERVERNAME started a backup - $nowdate" | tee -a $LOGFILE curl --data "content=$SERVERNAME started a backup - $nowdate" $WEBHOOK | tee -a $LOGFILE && echo "" >> $LOGFILE if pidof -o %PPID -x "backup.sh" then echo "Failed backup attempt on $SERVERNAME - $nowdate (rclone already running)" | tee -a $LOGFILE curl --data "content=Failed backup attempt on $SERVERNAME - $nowdate (rclone already running)" $WEBHOOK | tee -a $LOGFILE exit 1 fi rclone sync $FROM $TO -P --b2-hard-delete --stats 5s --progress | sed 's/Transferred:/\n\nTransferred:/' | tee -a $LOGFILE enddate=$(date -u) endtime=$(date +'%T') echo "Completed backup on $SERVERNAME - $enddate" | tee -a $LOGFILE curl -F "content=Completed backup on $SERVERNAME - $enddate" -F upload=@"$LOGFILE" $WEBHOOK | tee -a $LOGFILE if [ -f $LOGFILE ] then rm $LOGFILE fi