LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Executing commands remotely using scripts (https://www.linuxquestions.org/questions/linux-newbie-8/executing-commands-remotely-using-scripts-818675/)

imagine_me2 07-08-2010 06:08 AM

Executing commands remotely using scripts
 
For routine tasks i have to execute commands on machines running both winxp and linux. I usually do it via telnet. But the process is very manual as i have to authenticate for each machine then specify the command.

Is there any way that i could automate this job using a script or so?

Thanks.

grail 07-08-2010 06:14 AM

Quote:

Is there any way that i could automate this job using a script or so?
Might need to elaborate on 'this job' if you are expecting help.

Dinithion 07-08-2010 07:46 AM

This could most probably be achieved by using certificate as authentication instead of passwords, and writing a script.

Read about the 'expect' command to get some clue how a script would be written.

imagine_me2 07-08-2010 09:08 AM

job for example might be shutting down the machines during lunch.

grail 07-08-2010 09:17 AM

Maybe search for 'cron' then if you are looking to do something at the same time every period

imagine_me2 07-08-2010 09:59 AM

It definitely is periodic sometime but not always like suppose i would like to run swap my dhcp server from machine 1 to machine 2. I stop to dhcp server machine 1 and start dhcp server machine 2.

Expect is really nice , but i got some learning to do. I was "expecting" something easier.

Thanks.

Bratmon 07-08-2010 10:41 AM

ssh with key-based auth.

bsat 07-09-2010 03:35 AM

you could try using the putty tools, plink, pscp etc....

vigilandy 07-09-2010 04:40 AM

I agree with bratmon, ssh with certificate authentication is the way to go. From your desktop, create public and private key and then upload the public key to the server(s) you need to authenticate on. Then you can execute a local script to run remote commands via ssh.

For example:
Code:

ssh user@server1 remotecommand1
ssh user@server2 remotecommand2


imagine_me2 07-09-2010 07:34 AM

ssh sounds like the thing. But i don't know much about ssh. If you guys could please give me some references. I have a super slow net connection so direct links would be of much help.

Thanks

samsonite 07-09-2010 12:09 PM

What version of Linux are you using? Well it really doesn't matter that much. This link should help you to setup key based authentication.

http://wiki.centos.org/HowTos/Network/SecuringSSH

If you are familiar with the perl scripting language it can be done with the help of the expect module. http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod


All times are GMT -5. The time now is 07:55 PM.