0
votes

How to Create The bunch of Databases in Beeline using shell script by passing variables ?

I Have of list databases like abc,abcd,abcd3,abcd4 now i want to create this databases using shell script by passing variables?

1

1 Answers

0
votes
# define all database names in an array
dbs=(abcd abcd1 abcd2 abcd3)

# iterate over an array
for db in "${dbs[@]}"
do
   beeline -u <HIVE_SERVER2_URL> -n <username> -p <password> -e "create database $db"
done

Create a shell script with above code and replaces value for database url, username and password in beeline command and it should create database with the names in defined array

Alternatively if you have password stored in file then you can pass password file as well in beeline command. ex. beeline -u jdbc:hive2://localhost:10000/default -n jainik -w password_file