Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash script

#!/bin/bash
echo Hello World!
Comment

bash script

echo '#!bin/bash' > filename 
# works with and without extention, if you want extention do filename.sh
chmod +x filename
Comment

bash script

# The bash function below utilizes the CLI tool psql to vacuum analyze tables
# in a single schema which can be identified by either passing the name of
# the schema as the first parameter to the function
# or setting the environment variable PG_SCHEMA:
#

vacuum_analyze_schema() {
    # vacuum analyze only the tables in the specified schema

    # postgres info can be supplied by either passing it as parameters to this
    # function, setting environment variables or a combination of the two
    local pg_schema="${1:-${PG_SCHEMA}}"
    local pg_db="${2:-${PG_DB}}"
    local pg_user="${3:-${PG_USER}}"
    local pg_host="${4:-${PG_HOST}}"

    echo "Vacuuming schema `${pg_schema}`:"

    # extract schema table names from psql output and put them in a bash array
    local psql_tbls="dt ${pg_schema}.*"
    local sed_str="s/${pg_schema}s+|s+(w+)s+|.*/1/p"
    local table_names=$( echo "${psql_tbls}" | psql -d "${pg_db}" -U "${pg_user}" -h "${pg_host}"  | sed -nr "${sed_str}" )
    local tables_array=( $( echo "${table_names}" | tr '
' ' ' ) )

    # loop through the table names creating and executing a vacuum
    # command for each one
    for t in "${tables_array[@]}"; do
        echo "doing table `${t}`..."
        psql -d "${pg_db}" -U "${pg_user}" -h "${pg_host}" 
            -c "VACUUM (ANALYZE) ${pg_schema}.${t};"
    done
}
Comment

PREVIOUS NEXT
Code Example
Shell :: bash add new line to crontab 
Shell :: renaming a docker container 
Shell :: como instalar paquetes tar.gz en ubuntu 
Shell :: ubuntu make sh file executable 
Shell :: How to install specific Laravel version using composer 
Shell :: git delete unstaged files 
Shell :: linux shutdown 
Shell :: delay bash 
Shell :: edit grub file 
Shell :: how to check if docker is installed 
Shell :: awk if else statement 
Shell :: echo -e flag 
Shell :: poython opencv pip 
Shell :: run dotnet core app 
Shell :: install nginx mariadb php on mac 
Shell :: how to find empty folders linux 
Shell :: ubuntu arial font 
Shell :: windows terminal starting directory 
Shell :: how to reboot kali linux with commands 
Shell :: get podman ubuntu 
Shell :: get vscode extensions with ps1 
Shell :: bluetooth linux protocol not available 
Shell :: docker compose stop 
Shell :: ubuntu ram type 
Shell :: list all running processes linux 
Shell :: connect to a pod 
Shell :: how to add color in text github readme 
Shell :: docker execute command in container 
Shell :: httpd https docker 
Shell :: sudo add permissions to user 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =