Connect to database server and execute sql

I have a requirement and below is the detail.

  1. Create a shell script and needs to run in server "a".
  2. Connect to teradata database server "b".
  3. execute the .sql file from server "a" [sql file has only a select query]
  4. Save the output of the query to a file in server "a"
  5. Schedule this shell script to run every day for every 4 hours
  6. trigger email to specific ids once the .sh execution completes

Welcome to the forum.

Unfortunately, your request is quite generic, fuzzy. Any previous attempts on a solution from your side?

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.