×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Script automating dynamic queries in a remote host

Script automating dynamic queries in a remote host

Script automating dynamic queries in a remote host

(OP)
Hi everyone,

Since very long time, at work I need to repeat the same operations every time.
I've therefore decided to automate via script the following instructions, costs what it may:

  1. ask ID from prompt and store it locally
  2. ssh to remote host
  3. enter docker container
  4. launch DML queries using the previously stored ID
  5. this returns one row with another ID from the column 'id' which I need to use in the next command
  6. store result of a DML including the new ID into a csv
  7. copy the csv into a different path
  8. exit the docker container
  9. change permission on that file
  10. exit the ssh
  11. secure copy of the file from the remote host to the initial/current folder
It might look kind of tricky but the only point I see as problematic (on which I'm actually stuck) are 2, 3 and 5.
Here is what I've done so far:

CODE -->

#!/bin/bash
read -p "Enter the ID you would like to process: " my_id
ssh 10.10.10.10
sudo docker exec -it psql-db /bin/sh
psql -U postgres -d MY-DATABASE -c "SELECT * FROM all_cases WHERE id='my_id'";
#get the ID from the 'id' column and save it as 'new_id'
Copy (Select one, two, three FROM table WHERE id='new_id') To '/tmp/'new_id'.csv' With CSV DELIMITER '|' HEADER;
cp /tmp/'new_id'.csv /var/tmp/
exit
sudo chown user:user /opt/tmp/'new_id'.csv
exit
scp 10.10.10.10:/opt/tmp/'new_id'.csv . 

Any suggestion is welcome, feel free to change the logic and thank you in advance.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close