vsql error handling in shell scripting (No such file or directory)

I'm using shell scripting to upload a query's results to my database. In the script, first I save my query's results into a csv file and then upload the file into another database. After each step, I send a notification email to the user. The problem I'm facing is that I can't do a proper error handling. For example, I use something like the command below to generate the csv file: /apps/vertica/vertica_v5.1.6/bin/vsql -h server.my.com -U "user" -w "pass" -o "/data/test.csv" -c "select count(*), month from table1 group by month" If directory "data" does not exist, the exit status in Unix still returns 0 (operation successful even though an error occured) because the query results is shown on the screen. How can I handle such error? What kind of IF statement I should use in my script to capture it? Many thanks!

Comments

  • Hi! Use in redirection:
      $ pwd  /tmp/test  $ ls  $ vsql -Atqc "select * from all_tables" > /tmp/test/data/all_tables.csv  bash: /tmp/test/data/all_tables.csv: No such file or directory  $ mkdir data  $ vsql -Atqc "select * from all_tables" > /tmp/test/data/all_tables.csv  $   

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file