1

Well. I have a large basis on which to go. I just dont know how to go about it. using the exec() function. But I think I'd really just need help doing a remote SSH. The rest I already sorta understand

I have a perl script on 5 servers that need to be updated, and the best way to automate this is from the admin panel on a remote server.

The php file needs to collect the servers ips, username, passwords + the .pl's directory from a MySQL while also sending the post data that was just sent, and then send that data via SSH (from each variable) with the command to execute the remote perl script with the post data (from the php file) as an argument.

Basically: PHP(+post data) -> SQL(gets table info) -> perl -> (SSH -> perl)[repeat until no more servers are left to update]

The faster and simpler it does this, the better. If any steps can be removed to speed it up, then great, unless it makes it less secure.

I really do not get how to do much of this, as I'm still trying to learn Perl and SQL

user2012330
  • 55
  • 1
  • 6
  • 3
    StackOverflow is not the proper place for this question. We do not write your code for you. You need to do your own coding and if you aren't sure why something is not working as expected, post the code with an explanation of what you were expecting it to do, and what it is actually doing including all error messages. See [ask advice](http://stackoverflow.com/questions/ask-advice). – John Conde Feb 04 '13 at 02:16
  • Well. I have a large basis on which to go. I just dont know how to go about it. using the exec() function. But I think I'd really just need help doing a remote SSH. The rest I already sorta understand – user2012330 Feb 04 '13 at 02:32
  • Let's break this down, we can even make it yes/no. (1) Do you know PHP? (2) Do you know how to setup mysql? (3) Do you know how to work with mysql in php? (4) Do you know what the exec() function is? (5) do you know how to use the commandline through exec()? (6) do you know how to use ssh commandline? (7) Have you looked at [this](http://stackoverflow.com/questions/6270419/how-to-execute-ssh-commands-via-php) and seen if it answers your questions? and lastly, if all 1-6 are yes, and #7 is no, (8) in a single sentence that ends witha question mark, what is it that you want to know? – asifrc Feb 04 '13 at 02:50
  • 1 yes. 2. yes 3. yes 4. yes 5. sort-of 6. well enough to know what to do when logged in 7. just took a look. it kind of helps but not to terrifically. 8. how to tie it to a SQL db.. wow now that i look at it, my question seems dumb – user2012330 Feb 04 '13 at 04:27

1 Answers1

0

You can setup ssh password-less authentication between your servers, have your scripts setup and tested in the same path on different servers, and in your PHP script write

for($hostname in $hosts)
    system("ssh $hostname -c 'perl /path/to/my/script.pl'")

Or you could setup public/private key identity files and do:

for($hostname in $hosts)
    system("ssh $hostname -i ~/.ssh/identity_file -c 'perl /path/to/my/script.pl'")
Reza S
  • 9,480
  • 3
  • 54
  • 84