I connect usually to one enviornment "dev" daily and then ftp some files to some other enviorment "uat" and then login to "uat" and run some scripts to process these files.
I was thinking to automate the process, where running one script from "dev" will complete all task required to be done on "uat".
sftp part I have already automated. but a bit confused with ssh part.
I am able to login to uat from dev via ssh, but problem is
how to issue a series of command through a script once connected to remote uat?
I checked man pages and forum, but could not locate anything useful.
Any help will be highly appreciated.
Instead of initiating the process from "dev" i suggest running some script from "uat", that would make things easier. You can use "scp" (man scp) to collect the files from dev and don't have to think about ways to start processes remotely.
If you really need to do it the way you described it for some outside reason you could pack all the commands you want to run remotely into a script there and call this script via ssh (man ssh) using a command like "ssh -l username uat scriptname_to_execute.sh". This will login to machine uat as user "username" and execute the command "scriptname_to_execute.sh", then terminate the connection.
The reason why I wish to execute process from dev is... its not only uat the file need to be transferred there are many more...sys, rpt, prod etc...
if I go other way round , I end up running scripts from all env.
The idea mentioned of assembling all required commands in one script and fire it remotely is perfectly ok, but I my commands will be dynamic and based on
conditions like files found on dev.
One way to achieve same, I could create a dynamic script first ftp it, and then call via ssh. But I don't want to disturb file enviornment on remote creating temp files.
So we you can suggest any way where we pass bunch of commands to ssh, to be processed on remote will be good.
If I did not get it wrong, why can't you put the script in uat and run it remotely from dev? such as
[dev] $ ssh <id>@uat <the script file located in UAT>
You could print some debug statements in the script and redirect the output of the script to some local file. This should work.
i.e. as Tom said:
[dev] $ ssh <id>@uat <the script file located in UAT> >> /whatever/log/file/you/want