Snippets Collections
swagger_filepath=$1

json_content=$(yq -r -o=json "$swagger_filepath")
swagger_version=$(echo "$json_content" | jq -r '.swagger // ""')
openapi_version=$(echo "$json_content" | jq -r '.openapi // ""')

if [[ -n "$swagger_version" ]]; then
    basepath=$(echo "$json_content" | jq -r '.basePath // ""')
elif [[ -n "$openapi_version" ]]; then

    url=$(yq e '.servers[0].url' $swagger_filepath)

    before_string="//"

    find_char="/"

    before_string_index=$(awk -v a="$url" -v b="$before_string" 'BEGIN{print index(a,b)}')

    if [[ $before_string_index -ne 0 ]]; then
        substring=${url#*$before_string}

        find_char_index=$(awk -v a="$substring" -v b="$find_char" 'BEGIN{print index(a,b)}')

        if [[ $find_char_index -ne 0 ]]; then
            basepath="$find_char${substring#*$find_char}"
        else
            basepath=$find_char
        fi
    else
        basepath=$find_char
    fi

else
    echo "Unknown Swagger document version"
    exit 1
fi

echo "basepath = $basepath"
this command puts a symlink of .env in every docker-compose folder
it creates an extra .env with a ~ like .env~ if the file already exists. Just ignore it. I could create a line of code that removes it

find /mnt/docker/docker-compose-files/ -mindepth 1 -maxdepth 1 -type d -exec ln -sbf /mnt/docker/docker-compose-config/.env {}/.env \;

remove every .env~ file in every docker-compose folder

find /mnt/docker/docker-compose-files/ -mindepth 1 -maxdepth 1 -type d -exec rm {}/.env~ \;

create a symbolic link in one specified directory

ln -sbf /mnt/docker/docker-compose-config/.env /mnt/docker/docker-compose-files/mongodb/.env

find the .env file in specified directory

find /mnt/docker/docker-compose-files -name .env
#!/bin/bash
MYIP=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
for i in $(docker ps --format '{{.Names}}'); do
    docker port $i | grep -oP '(?<=0:)[1-9].*' | while read -r MYPORT; do
        if [[ -n $MYPORT ]]; then
            MYRESPONSE=$(curl -Is --max-time 0.5 $MYIP:$MYPORT | head -1 | grep -oP '[0-9][0-9][0-9]')
            pat="2|3"
            if [[ ${MYRESPONSE:0:1} =~ $pat ]]; then
                printf "| %20s | %-20s | %-10s | \n" "$i" "$MYIP:$MYPORT" "$MYRESPONSE"
            fi
        fi
    done
done
#!/bin/bash
#####################################################################
#Author:Irfan Khan
#Description:this function will used to donwload & move that file to
#desired location
#####################################################################
download(){
    #$url=$1
    wget -cO - https://gist.github.com/chales/11359952/archive/25f48802442b7986070036d214a2a37b8486282d.zip > dbtest.zip
    if [[ -f dbtest.zip ]];
    then
        mv dbtest.zip ./mydb_data
        exit 0
    else
        echo "hey file not moved some thing went wrong.."
    fi
}

download  #calling the function
#To Download File From Remote Server To Local Machine Using SCP.using Powershell or gitbash 
scp -i .\keys.pem ubuntu@XX.XX.XX.XX:/home/ubuntu/Dir/fileName  C:\Users\USER\Downloads\
#!/bin/bash
# Bash Menu Script Example

PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo "you chose choice 1"
            ;;
        "Option 2")
            echo "you chose choice 2"
            ;;
        "Option 3")
            echo "you chose choice $REPLY which is $opt"
            ;;
        "Quit")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done
star

Sat Jun 24 2023 21:15:59 GMT+0000 (Coordinated Universal Time)

#shellscript
star

Sat Apr 02 2022 08:51:08 GMT+0000 (Coordinated Universal Time)

#shellscript
star

Sat Mar 26 2022 12:18:07 GMT+0000 (Coordinated Universal Time)

#shellscript
star

Wed Feb 09 2022 12:29:41 GMT+0000 (Coordinated Universal Time)

#linux #shellscript #function #wget #download
star

Wed Feb 09 2022 12:16:12 GMT+0000 (Coordinated Universal Time) own

#linux #shellscript #scp #copy
star

Mon Oct 18 2021 07:57:50 GMT+0000 (Coordinated Universal Time) https://askubuntu.com/questions/1705/how-can-i-create-a-select-menu-in-a-shell-script

#bash #sh #script #shell #shellscript

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension