Home Blog About Me Resume

My First Bash Script

Introduction:

Nowadays IT business environments are fast-paced to help processes of repetitive tasks go faster lots of businesses are starting to utilize scripts to automate these tasks. A common task for businesses is uploading files to Azure Storage solutions. Uploading files manually to Azure Storage can be time-consuming and error-prone. The need for an automated solution led to me developing a Bash script that leverages the power of the Azure CLI. In the following blog post, I will explain my process for making such a script to automate this task as well as how the script works.

The Script:

upload_script.sh

The upload_script.sh Bash script acts as a bridge between your local environment and Azure Storage. The core key components and functionalities that make it work are:

Authentication:

The script has a simple authentication process by installing the Azure CLI and authenticating users via device code authentication.

(Displays login information and lets you know that you're logged in)

Region Selection and Resource Group Handling:

Users are prompted to choose a region from a list of recommendations. The script then checks for the existence of a specified resource group and dynamically creates a new one if needed.

Storage Account and Container Handling:

Flexibility is a key feature of the script. It provides options to create new storage accounts and containers or use existing ones. Name uniqueness is ensured, enhancing user experience.

File Handling:

The heart of the script lies in its ability to handle files. Users can upload a single file using the -s option or multiple files using the -m option. The script checks for existing files, offers options for overwriting, skipping, or renaming, and generates shareable links (SAS tokens) for the uploaded files.