On Wed, Jan 18, 2012 at 5:31 AM, charith <charith...@gmail.com> wrote:
> Hi All, > > I create following bash script to run some block of commands on remote > server > and get information but I try to do same using Perl but I couldn't > make it so any one can suggest way to get done this using perl ? (please > without using any modules) > > my .sh........................... > > > > ssh -T $LOGIN <<EOI > > cd /x02/oracle/downloads > > find ./ -type d | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/' > >>DirectoryStructure.txt > > cat DirectoryStructure.txt > > exit > > EOI > > thanks > The simplest way to do this is to use the exec command it is not the right way by any means but it should work most of the time. The main problems you will find is that you cannot do much error handling, you would basically only be able to see if your script executed SSH correctly or not and that is all that you would be able to do... As far as output you should be able to capture that but it would be just plain old flat text any other work you might want to do with it you would have to do using regular expressions etc... All in all it is not a nice solution, but if you really cannot use modules then you are likely stuck with it. I would advise you to have a look at the Net::OpenSSH module. I know you said no modules but hear me out... Net::OpenSSH is a pure perl module that doesn't have any mandatory dependencies (obviously, besides requiring OpenSSH binaries). This means that you could include it as a part of your program as a module that does not need installing as there is no need to do this. Of course you will have to go into the gutts of the module and find out how it calls the OpenSSH binaries and make sure that you deal with a situation where the binaries are in another location then the one on your machine and of course the case where the are not installed at all. It is going to be a nasty thing and you will have to deal with solving the same problem over and over again with every new release of the Net::OpenSSH module you want to use... You also will need to deal with stuff like outdated versions of OpenSSH and other such wonderful situations. Personally I would not go this route but it really depends on what you need to do if all you need is just a directory listing the exec command might be enough, if you are looking for more things and need to do proper error handling then you will most likely need to find a way to deal with a module anyway. By the way, if you are using SSH to connect to remote machines why could you not simply run this on a single machine? This would make your life a lot simpler as getting a module installed on a single machine is a lot less arguing with the administrator of the server park then getting it installed on a lot of machines. After all if you are to use perl but have to live without modules then what is the point... Perl without modules is like C/C++ without external libraries it will work but it is going to be a massive pain in the rear and likely a very difficult slow and error prone job. Regards, Rob