admin管理员组文章数量:1344319
#!/bin/bash
# Set paths and variables
JAVAPATH=/usr/java/latest/bin/java
PRESTO_JAR_PATH=/data2/pqr/presto/trino
PRESTO_SERVER=https://a.b.c.d:9443
USER=pqrxyz
PASSWORD="pwdenb\$1207" # Password with $ symbol correctly escaped
PRESTO_CATALOG=xyzp
PRESTO_SCHEMA=cmlop
TABLE_NAME=test_table
filename_tmp=utcrj.csv
current_time=$(date +%s)
logfileName=$current_time
logfileName+="_trino_error.log"
logfile="/data2/pqr/dev/logs/$current_time.txt"
query="select * from test_table limit 100"
# First, login and execute the query using the full password
echo "Logging in and executing query..."
/usr/bin/expect <<EOD
set timeout -1
spawn $JAVAPATH -Xmx1G -jar $PRESTO_JAR_PATH \
--server $PRESTO_SERVER \
--user $USER \
--password $PASSWORD \
--catalog $PRESTO_CATALOG \
--schema $PRESTO_SCHEMA \
--debug \
--execute "$query" \
--output-format TSV_HEADER \
> "/data2/pqr/dev/$filename_tmp" \
2> "/data2/pqr/dev/logs/$logfileName"
# Handling password prompt (this step is inside the expect block above)
expect {
"Password for user $USER:" {
send "$PASSWORD\r"
}
timeout {
puts "Timed out waiting for password prompt"
exit 1
}
}
expect eof # Wait for the end of the spawned process
EOD
runStatus=$?
# Check if the command was successful
if [ $runStatus -ne 0 ]; then
echo "Error executing query. Please check logs."
exit 1
fi
# Convert TSV to CSV
echo "Converting TSV to CSV..."
sed 's/\t/,/g' "/data2/pqr/dev/$filename_tmp" > "/data2/pqr/dev/DailyTrend.csv"
# Clean up temporary file
echo "Cleaning up temporary files..."
rm /data2/pqr/dev/$filename_tmp
echo "Process completed successfully!"
While trying to execute the above sh script, I get the below error
Password is matching with the one I have
can't read "1207": no such variable
while executing
"spawn /usr/java/latest/bin/java -Xmx1G -jar /data2/cgnat/presto/trino --server https://a.b.c.d:9443 --user b0267175 --pa..."
I tried removing $ from script, but it still did not work.
本文标签:
版权声明:本文标题:java - While executing script to execute a query, getting can't read "1207": no such variable - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743764057a2534911.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论