LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 06: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, 06:14 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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, 07: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, 09: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, 09:17 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Maybe search for 'cron' then if you are looking to do something at the same time every period
 
Old 07-08-2010, 09: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, 10: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, 03: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, 04: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, 07: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, 12: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



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 09:27 AM
Executing a *.bin file remotely on Linux AndrewNew Linux - Newbie 3 05-15-2008 05:38 AM
Executing scripts jonette20 Linux - General 3 10-15-2007 01:50 PM
executing Bash Scripts c4nk Linux - General 3 03-11-2007 04:52 PM
Executing X-Programs remotely frankieboy Linux - General 3 10-08-2003 02:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:04 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
Open Source Consulting | Domain Registration