I have written the following code using three different ide . The code is simple it creates the database on hive, but the database name will be dynamic.
#!/bin/bash
year=`date +%Y`
month=`date +%m`
day=`date +%d`
echo ${year}
echo ${month}
echo ${day}
dbname=dynamic_hive_${year}_${month}_${day}
echo ${dbname}
hive -e "create database if not exists ${dbname}; use ${dbname}; drop table bins_1; CREATE TABLE bins_1 (firstname string);"
I uploaded this code in our environment and ran it using the java program. The java program uses the java Runtime.exec to run the script. When I see the logs though, the result is as below:
Here I am getting a space in between each echo and the database name is also not as expected. If I manually run the uploaded file doing sh testfile.sh, then I get the following result:
The database is printed but it is so weird and not as expected. In the error we can see the database is not being able to be parsed. I think the new line appears after 2020 so it does not get parsed.
If the same code I copy in my server, by doing vim and run it then it runs absolutely fine. I am so confused and I really don't know what I am missing out. This should be fairly simple but I am missing out something. If someone could help me out, I would really appreciate it.