Shell: Get The Data From Remote Host And Excute Some Other Commands
I need to create a shell script to do this:
- ssh to another remote host
- use sqlplus on that host and spool command to get the data from oracle db into a file
- transfer the file from that host to my host
- excute another shell script to process the data file
I have finished the 4th step shell script. Now I have to do this 4 steps one by one. I want to create a script and do them all. Is that possible? How to transfer the data from one host to my host?
I think maybe the db file is not necessary.
Note: I have to ssh to anot开发者_如何学运维her host to use sqlplus. It is the only one host which have the permission to access database.
# steps 1 and 2
ssh remote_user@remote_host 'sqlplus db_user/db_pass@db @sql_script_that_spools'
# step 3
scp remote_user@remote_host:/path/to/spool_file local_file
# step 4
process local_file
Or
# steps 1, 2 and 3
ssh remote_user@remote_host 'sqlplus db_user/db_pass@db @sql_script_no_spool' > local_file
# step 4
process local_file
Or, all in one:
ssh remote_user@remote_host 'sqlplus db_user/db_pass@db @sql_script_no_spool' |
process_stdin
Well Glenn pretty much summed it all up.
In order to make your life easier, you may want to also consider setting up passwordless ssh. There is a slightly higher security risk associated with this, but in many cases the risk is negligible.
Here is a link to a good tutorial. It is a debian based tutorial, but the commands given should work the same on most major linux distros.
精彩评论