Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

run perl script on remote server

by sumit07 (Novice)
on Sep 08, 2012 at 04:35 UTC ( #992425=perlquestion: print w/replies, xml ) Need Help??
sumit07 has asked for the wisdom of the Perl Monks concerning the following question:

Hi perl monks I really need a help from u all. I have a scenario where there are 3 servers. My perl script is in server A, my files are in server B and I want to run the perl script present in server A from command line in server C to manipulate the files in server B. How can i accomplish this task. Any help will be appreciated. Thanks

Replies are listed 'Best First'.
Re: run perl script on remote server
by bitingduck (Chaplain) on Sep 08, 2012 at 05:32 UTC

    If you're running from the command line on server C, why can't you just ssh into server A where your script is and run from the command line there? The script can also ssh over to server B to manipulate your files. If you set things up with ssh public/private keypairs, you can do it without having to store passwords anywhere. You might want to use Net:SSH in your scripts. It's not clear that there's much perl-specific in the question.

      for ssh to server A do we need another software lyk putty or cygwin
        This is the first clue you have given that you are running Windows machines.

        IF these machines are on the same domain, and/or IF your login credentials on C have access to the shares on A and B, you can do something like this from the command-line on machine C:

        C:\> perl \\A\Path\to\code\share\ \\B\path\to\data\Dat +afile.fil
        Then your prograam can use the diamond operator to access the file, without being programmed explicitly for file access on a remote machine.

        If the machines do not have explicit shares, and if you have administrator priviledges,
        You can access the "hidden" shares at the root of the drive like:

        Note : C$ indicates the C:\ drive.

                     I hope life isn't a big joke, because I don't get it.

        I have no idea how to do things in windows-- it's pretty straightforward on a typical *nix setup. NetWallah and Anonymous Monk both posted suggestions that will likely work with windows.

Re: run perl script on remote server
by Rudolf (Pilgrim) on Sep 08, 2012 at 04:56 UTC

    Hello sumit07, so as far as I understand the main communication between you and the program will be happening through server C's command line and that the actual interaction will be going on between servers A and B. A would be manipulating the files in B. The first thing I would suggest is setting up something to listen on server A for incomming messages from you (c). I am not sure if these servers are on the same machine or LAN though it would not really matter there is more than one way to do it anyway.

    After you set up a socket to listen for messages on A, you can create a sort of opcode for each function you want executed... maybe you might say "delete filex.txt" on C and that would get sent to A, where a regex can check socket for relevant opcodes and you can preform the function to server B accordingly.

    Now this is all assuming you know how to work with sockets but if you do not, there are some easy ways like IO::Socket::INET or you can simply use socket; and build one from scratch. I also do not know what kind of servers your running but for machine to machine communication definetly look at sockets. If they are all on the same machine take a look at piping and other forms of inter process communication.

      thanks Rudolf for ur quick reply. First thing is that servers are in different machines. now to run perl script locally we write perl <filename> but in this case how to call it in remote machine could u plz clarify

        Ah, okay the clarification definetly helps. I do not believe there is any other way to send your command over to the server without using another piece of software however depending on the server type itself, you can set up something to listen for you and you can then write to that program ( via TCP connection ) something like you would regularly on your local machine- "perl <filename>" and if you can set up server A to run a system command of the collected data from the socket, it will send "perl <filename> to its local command line.

        It would be important to note what kind of servers they are? Also it would make things a lot easier if they were made out of perl hehe.

        Best of luck though, - Rudolf

Re: run perl script on remote server
by NetWallah (Canon) on Sep 08, 2012 at 06:10 UTC
    Why don't you just NFS-mount the required data and code nfs-shares onto the "C" machines, which will then have visibility to all necessary resources ?

                 I hope life isn't a big joke, because I don't get it.

Re: run perl script on remote server
by Anonymous Monk on Sep 08, 2012 at 14:54 UTC

    Why can't you copy the script from server A to either server B or server C ("client")? If you can mount server B's files on the client, over the network (NFS, SMB), you can run the script on the client. If you can't, you must run the script on server B.

    There's no such thing as manipulating a remote file system without some sort of file-sharing glue in between.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://992425]
Approved by kcott
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-03-25 04:24 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (300 votes). Check out past polls.