aws list of auto scaling groups

Here’s a script to list Auto Scaling Groups from multiple AWS accounts. Accounts are in your AWS profiles. #!/bin/bash file='results-aws-asg.txt' > $file declare -a account=("default" "account-1" "account-2" "account-3" "account-4" "account-5") declare -a region=("us-east-1" "us-east-2" "us-west-1" "us-west-2") for i in "${account[@]}" do echo '----------------------' >> $file echo 'Account: '$i >> $file for j in "${region[@]}" do echo 'Region: '$j >> $file aws autoscaling describe-auto-scaling-groups \ --query "AutoScalingGroups[].[AutoScalingGroupName,LaunchConfigurationName]" \ --profile $i \ --region $j \ --output text >> $file done done

January 27, 2023 · 1 min · ulysses

logging in to aws and gcp

Here’s my Bash script to login to both AWS and GCP. It has a little bit of intelligence. It checks if you are already logged in, and skips if you are. If not logged in, it will open up the cloud web console which is protected by Okta. The script has been redacted and replace with generic usernames and web pages for security reasons. #!/bin/bash ## CHECK IF LOGGED IN TO GCP read -p "Login to GCP? (y/n) : " login_gcp if [[ $login_gcp = "y" ]]; then file1="/Users/username/code/etc/auth-gcp.txt" gcloud auth print-identity-token 1> /dev/null 2> $file user=$(gcloud config list account --format "value(core.account)") auth=$(cat "$file" | head -n 1) rm -f $file1 if [[ $auth == "Reauthentication required." ]] || [[ $user != "first.last@domain.com" ]]; then echo "Logging in to Google Cloud Platform." gcloud auth login gcloud auth application-default login open https://okta-login else echo "You are already logged in to Google Cloud Platform." fi else echo "Skipping GCP ... " fi ## CHECK IF LOGGED IN TO AWS read -p "Login to AWS? (y/n) : " login_aws if [[ $login_aws = "y" ]]; then file2=""/Users/username/code/etc/auth-aws.txt"" aws sts get-caller-identity 2> $file2 expired=$(tail -n +2 "$file2") rm -f $file2 if [[ $expired =~ "expired" ]] || [[ $expired =~ "Unable" ]]; then open https://okta-login echo "please wait until web page loads ... " read -p "Press any key to continue... " -n1 -s echo "" basecred='/Users/username/.aws/credentials.base' newcreds='/Users/username/Downloads/credentials' creds='/Users/username/.aws/credentials' if [ ! -f $newcreds ]; then echo 'No AWS credentials.' exit else cat $newcreds $basecred > $creds echo 'New AWS credentials.' sleep 3 rm -f $newcreds fi else echo "You are already logged in to AWS." fi else echo "Skipping AWS ... " fi

January 22, 2023 · 2 min · ulysses

aws create volume from snapshot with tags

Here’s another script that creates a volume from a snapshot, but also add the tags. #!/bin/bash read -p "server : " server read -p "volumeId : " volume read -p "snapshotId : " snapshot read -p "region : " region read -p "zone : " zone read -p "profile : " profile # get tags tags1=$(aws ec2 describe-volumes --volume-ids $volume --query 'Volumes[].Tags[]' --region $region --profile $profile) # remove quotes tags2=$(echo "$tags1" | tr -d '"') # remove spaces tags3=$(echo $tags2 | sed 's/ //g') # replace : with = tags4=$(echo $tags3 | sed 's/:/=/g') # if empty value replace with quotes tags5=$(echo $tags4 | sed 's/Value=}/Value=""}/g') # create volume aws ec2 create-volume \ --availability-zone $zone \ --encrypted \ --iops 3000 \ --volume-type gp3 \ --snapshot-id $snapshot \ --tag-specifications 'ResourceType=volume,Tags='$tags5'' \ --region $region \ --profile $profile

January 19, 2023 · 1 min · ulysses

aws create volume from snapshot

Here’s a bash script that creates a volume from a snapshot in AWS. #!/bin/bash read -p "snapshotId : " snapshot read -p "server : " server read -p "tag1 : " tag1 read -p "tag2 : " tag2 read -p "region : " region read -p "zone : " zone read -p "profile : " profile aws ec2 create-volume \ --availability-zone $zone \ --encrypted \ --iops 3000 \ --volume-type gp3 \ --snapshot-id $snapshot \ --tag-specifications "ResourceType=volume,Tags=[{Key=Name,Value="$server"},{Key=tag1,Value="$tag1"},{Key=tag2,Value="$tag2"}]" \ --region $region \ --profile $profile

January 18, 2023 · 1 min · ulysses

checking nameservers

Handy little script to see if nameserver is on an array. #!/bin/bash declare -a servers=("127.0.0.53" "127.0.0.52" "127.0.0.51") client=$(cat /etc/resolv.conf | grep nameserver) for i in "${servers[@]}" do if [[ $client =~ $i ]] then using_unbound="true" break else using_unbound="false" fi done echo $using_unbound "|" $client

January 15, 2023 · 1 min · ulysses

windows curl command

If you have to download a file from the Internet on a Windows server, can certainly use the browser. But if the browser is rendering the file instead of downloading them, you may have to use the curl command which is already pre-installed on most Windows servers. Just open the command line. Here’s the the curl command to download a file. curl.exe --output index.txt --url https://website.domain/index.txt

January 11, 2023 · 1 min · ulysses

aws list account aliases

Here’s how to list account aliases. I have four profiles in my credentials. I’m looping through all four and printing the aliases. #!/bin/bash file='results-aws-account-aliases.txt' > $file declare -a account=("default" "one" "two" "three") for i in "${account[@]}" do echo '----------------------' >> $file echo 'Account: '$i >> $file aws iam list-account-aliases \ --profile $i done

December 26, 2022 · 1 min · ulysses

linux screen

Just documenting the Linux Screen command. Install screen first. yum install screen dnf install screen apt install screen zypper install screen Start a new screen. screen -S one screen -S two screen -S three Detach from screen. Ctrl+a+d List active screens. screen -ls There is a screen on: 15575.one (Detached) 15581.two (Detached) 15593.three (Detached) 1 Socket in /var/run/screen/S-root. Reattach to an existing screen. screen -r one screen -r two screen -r three If there’s only one active screen, you can run screen -r without the name. ...

December 26, 2022 · 1 min · ulysses

linux mint vera

I upgraded to Linux Mint Vera from Una. ulysses@penguin:~/Code$ neofetch ...-:::::-... ulysses@penguin .-MMMMMMMMMMMMMMM-. --------------- .-MMMM`..-:::::::-..`MMMM-. OS: Linux Mint 21.1 x86_64 .:MMMM.:MMMMMMMMMMMMMMM:.MMMM:. Kernel: 5.15.0-56-generic -MMM-M---MMMMMMMMMMMMMMMMMMM.MMM- Uptime: 13 hours, 35 mins `:MMM:MM` :MMMM:....::-...-MMMM:MMM:` Packages: 2176 (dpkg) :MMM:MMM` :MM:` `` `` `:MMM:MMM: Shell: bash 5.1.16 .MMM.MMMM` :MM. -MM. .MM- `MMMM.MMM. Resolution: 3840x2160 :MMM:MMMM` :MM. -MM- .MM: `MMMM-MMM: DE: Cinnamon 5.6.5 :MMM:MMMM` :MM. -MM- .MM: `MMMM:MMM: WM: Mutter (Muffin) :MMM:MMMM` :MM. -MM- .MM: `MMMM-MMM: WM Theme: Mint-Y-Dark-Aqua (Mint-Y) .MMM.MMMM` :MM:--:MM:--:MM: `MMMM.MMM. Theme: Mint-Y-Aqua [GTK2/3] :MMM:MMM- `-MMMMMMMMMMMM-` -MMM-MMM: Icons: Mint-Y-Aqua [GTK2/3] :MMM:MMM:` `:MMM:MMM: Terminal: gnome-terminal .MMM.MMMM:--------------:MMMM.MMM. CPU: AMD Ryzen 7 1700X (16) @ 3.700GHz '-MMMM.-MMMMMMMMMMMMMMM-.MMMM-' GPU: AMD ATI Radeon R7 240/340 / Radeon 520 '.-MMMM``--:::::--``MMMM-.' Memory: 3864MiB / 15928MiB '-MMMMMMMMMMMMM-' ``-:::::-`` I have 2 issues out of the gate. ...

December 23, 2022 · 2 min · ulysses

linux mint upgrade

Here’s how to upgrade your Linux Mint Desktop. sudo apt update sudo apt install mintupgrade Then run the upgrade. sudo mintupgrade

December 20, 2022 · 1 min · ulysses