Loading...
More Shell Posts
for region in `aws ec2 describe-regions --output text | cut -f4`doecho -e "\nListing Instances in region:'$region'..."aws ec2 describe-instances --query 'Reservations[*].Instances[*].{Instance:InstanceId,Subnet:SubnetId}' --region $regiondone#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
# Three ways of checking if a file exists in a shell scriptFILE=/etc/resolv.confif test -f "$FILE"; thenecho "$FILE exists."fiif [ -f "$FILE" ]; thenecho "$FILE exists."fiif [[ -f "$FILE" ]]; thenecho "$FILE exists."fi
#!/bin/bash#Makes a directory ./monkeys and puts every single bored bored ape yacht club monkey in there#Leif Messingerlet OFFSET=0let BATCHSIZE=50let LIMIT=100mkdir monkeysfunction parseResults(){sed 'y/,/\n/' | sed -e '/storage.opensea/d' -e '/https:\/\/lh3.googleusercontent.com\/Ju9CkWtV-1Okvf45wo8UctR-M9He2PjILP0oOvxE89AyiPPGtrR3gysu1Zgy0hjd2xKIgjJJtWIc0ybj4Vd7wv8t3pxDGHoJBzDB=s120/d' | egrep '"image_url":"(.*)"' | tr -d '\"' | sed 's/image_url://'}function downloadMonkeys(){while read -r line; doname=`echo "$line" | sed 's/https:\/\/lh3.googleusercontent.com\///'`wget -q -O "./monkeys/$name.png" "$line" &done}function queryMonkeys(){let progress=($OFFSET*100)/$LIMITecho "Progress: $progress%"result=`curl -s --request GET --url "https://api.opensea.io/api/v1/assets?order_direction=desc&offset=$OFFSET&limit=$BATCHSIZE&collection=boredapeyachtclub"`if [[ "$result" =~ "Request was throttled" ]] || [ "$result" == "" ]; then#Retry downloadsleep 10else#Download Monkeysecho "$result" | parseResults | downloadMonkeyslet OFFSET+=$BATCHSIZEfi#If not out of bounds, recurseif [ "$OFFSET" -lt "$LIMIT" ] || [[ "$result" =~ '"assets":[]' ]]; thenqueryMonkeysfi}echo "Downloading your monkeys into ./monkeys asynchronously."queryMonkeys
#!/bin/bash# Recursively find all .svelte files in the current directory and its subdirectoriesfind . -type f -name "*.svelte" -o -name "*.html" -o -name "*.htm" | while read file; do# Replace all h1 tags with the specified formatsed -i 's/<h1>\(.*\)<\/h1>/<h1 id="\1">\1<\/h1>/g' "$file"# Replace all h2 tags with the specified formatsed -i 's/<h2>\(.*\)<\/h2>/<h2 id="\1">\1<\/h2>/g' "$file"# Remove whitespace from the id attribute valuefor i in {0..10} ; dosed -i 's/\(id="[^"]*\)\W\([^"]*"\)/\1\2/g' "$file"donedone
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"
#!/bin/bash#Originally made by Isaac Cook https://gist.github.com/icook/5400173#Modified by Leif Messinger#upload_key.sh [server_ip [server2_ip [...]]]#To be run locally on a linux computerif [ -e ~/.ssh/id_rsa.pub ];thenecho "SSH Key already exists on local machine"elseecho "Generating SSH key on local machine"ssh-keygen -t rsa #generates id_rsa and id_rsa.pubchmod -R 700 ~/.ssh #Sets permissions of ssh folderssh-add #Adds keys (and passwords?) to ssh_agent. (hopefully doesn't require password)fiecho "Loading client public key into memory"pubKey=$(<~/.ssh/id_rsa.pub)for serverdoecho "Adding client public key to $server remote server authorized keys"#Idiot Isaac Cook didn't know about ssh-copy-id#ssh-copy-id even checks if your key already exists#In fairness, I didn't either until researching ssh-addssh-copy-id -i ~/.ssh/id_rsa.pub $server #In theory, this should prompt for a username#ssh $server "mkdir -p ~/.ssh; #Make the folder if not already made# echo \"$pubKey\" >> ~/.ssh/authorized_keys; #Append your public key to the server's authorized_keys# chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" #Set the correct permissions of those files#echo "Adding server public key to local authorized keys"#ssh $server "ssh-copy-id -i ~/.ssh/id_rsa.pub \$SSH_CLIENT" #this might need some awk, as $SSH_CLIENT spits out clientip portnumberecho "Displaying server public key"ssh $server "cat ~/.ssh/id_rsa.pub"#Though, he did give me a good ideaecho "Displaying keys authorized on $server (you can paste them in your authorized_keys file)"ssh $server "cat ~/.ssh/authorized_keys"#echo "Appending keys authorized on $server to your local authorized_keys"#ssh $server "cat ~/.ssh/authorized_keys" >> ~/.ssh/authorized_keysdoneecho "SSH keys schronized successfully!"