Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Help with a quick script.

  • 18-08-2002 05:34PM
    #1
    Registered Users, Registered Users 2 Posts: 158 ✭✭


    Ok, it's been a while, and I'm getting extremely lazy... but

    Here's the deal.

    I need to write a script which remotely accesses one machine from another and launch a said process on the remote box.

    For example, telnet/ssh to a unix server and start an X process.

    Any help much appreciated.

    P.S. It might be noted that I don't have a homedir on the remote machine, instead I simply have a login.


Comments

  • Closed Accounts Posts: 6,601 ✭✭✭Kali


    could do worse than use the Net::Telnet module for Perl...

    use Net::Telnet;
    $telnet = Net::Telnet->new
    (
    Timeout=>90,
    Prompt =>'%',
    Host => 'remotehost.com'
    );

    $telnet->login('username','password');
    $telnet->cmd("cd directory");
    $telnet->cmd("remotecommand");
    $telnet->close;

    and add that as a cron job if you want it done on a daily or whatever basis.

    disclaimer: theres nearly always a much easier way then the ways I come up with.


  • Registered Users, Registered Users 2 Posts: 1,038 ✭✭✭rob1891


    I think using expect would be the bog standard way of doing this. man expect and read up on it :P But if you've got perl ...


  • Registered Users, Registered Users 2 Posts: 171 ✭✭Wookie


    Use remote execution.

    Once you have set up server A on server B, server A can execute scripts on server B.

    Once setup it might be a little easier to use than the perl option.


  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    If you have ssh on both machines, then simply type
    ssh user@machineB '/bin/sh /home/fred/scripts/run.sh'. This will just log in and execute the command and then exit the shell.


  • Registered Users, Registered Users 2 Posts: 1,848 ✭✭✭flamegrill


    Originally posted by lynchie
    If you have ssh on both machines, then simply type
    ssh user@machineB '/bin/sh /home/fred/scripts/run.sh'. This will just log in and execute the command and then exit the shell.

    The use of keys with ssh would allow you to do this from cron without the need to input a password.


  • Advertisement
Advertisement