LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-08-2010, 07:08 AM   #1
imagine_me2
Member
 
Registered: Nov 2009
Location: Kolkata, India
Distribution: Fedora 11
Posts: 136

Rep: Reputation: 22
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.
 
Old 07-08-2010, 07:14 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
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.
 
Old 07-08-2010, 08:46 AM   #3
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
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.
 
Old 07-08-2010, 10:08 AM   #4
imagine_me2
Member
 
Registered: Nov 2009
Location: Kolkata, India
Distribution: Fedora 11
Posts: 136

Original Poster
Rep: Reputation: 22
job for example might be shutting down the machines during lunch.
 
Old 07-08-2010, 10:17 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
Maybe search for 'cron' then if you are looking to do something at the same time every period
 
Old 07-08-2010, 10:59 AM   #6
imagine_me2
Member
 
Registered: Nov 2009
Location: Kolkata, India
Distribution: Fedora 11
Posts: 136

Original Poster
Rep: Reputation: 22
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.
 
Old 07-08-2010, 11:41 AM   #7
Bratmon
Member
 
Registered: Jul 2009
Location: 75.126.162.205:80
Distribution: Arch / Mint 17
Posts: 297
Blog Entries: 3

Rep: Reputation: 50
ssh with key-based auth.
 
Old 07-09-2010, 04:35 AM   #8
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
you could try using the putty tools, plink, pscp etc....
 
Old 07-09-2010, 05:40 AM   #9
vigilandy
Member
 
Registered: Mar 2010
Location: Tokyo
Distribution: Arch, Fedora
Posts: 71

Rep: Reputation: 23
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
 
Old 07-09-2010, 08:34 AM   #10
imagine_me2
Member
 
Registered: Nov 2009
Location: Kolkata, India
Distribution: Fedora 11
Posts: 136

Original Poster
Rep: Reputation: 22
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
 
Old 07-09-2010, 01:09 PM   #11
samsonite
LQ Newbie
 
Registered: Feb 2010
Posts: 5

Rep: Reputation: 1
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
executing db2diag remotely engee AIX 3 11-30-2009 10:27 AM
Executing a *.bin file remotely on Linux AndrewNew Linux - Newbie 3 05-15-2008 06:38 AM
Executing scripts jonette20 Linux - General 3 10-15-2007 02:50 PM
executing Bash Scripts c4nk Linux - General 3 03-11-2007 05:52 PM
Executing X-Programs remotely frankieboy Linux - General 3 10-08-2003 03:31 AM


All times are GMT -5. The time now is 02:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration