LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-03-2018, 01:35 AM   #1
prakash0106
LQ Newbie
 
Registered: Jan 2009
Posts: 15

Rep: Reputation: 1
I want to execute the command remotely


my test is I have server name with different domain name :
example: test.server.com and test.servera.com, test.serverb.com

I want to execute the command remotely with help of expect and spawn

#!/usr/local/bin/expect -f
spawn ssh username@test.server.com
if(not reachable){
spawn ssh username@test.servera.com
}else{
echo "it failed\r"
}
 
Old 08-03-2018, 01:59 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by prakash0106 View Post
I want to execute the command remotely ...
You're probably better starting a new thread then. But to get you started, there are several ways:

Code:
#!/bin/sh

ssh -i /home/prakash/.ssh/servera_key_rsa username@test.servera.com "uname -nrs;" \
|| ssh -i /home/prakash/.ssh/serverb_key_rsa username@test.serverb.com "uname -nrs;"

if [ $? -eq 0 ]; then 
        echo It Worked; 
else 
        echo Did Not Work; 
fi
Please explain more of what you are trying to do. Using expect is almost certainly barking up the wrong tree.
 
Old 08-03-2018, 02:17 AM   #3
prakash0106
LQ Newbie
 
Registered: Jan 2009
Posts: 15

Original Poster
Rep: Reputation: 1
really sorry for posting the help on this post. I havnt time to open a new post query.


I have list of servers with 2 different domain name.

pp1.servera.com
pp1.serverb.com

pp2.servera.com
pp2.serverb.com

......

single host with 2 different domain alias names for R&D purpose

now im trying to execute the remote command for file modification with help of expect and spawn

in my environment sometimes pp1.servera.com will login and pinging so no issues for executing the scripts with x.servera.com but sometimes pp1.servera.com not reachable and pp1.serverb.com will reaching. so I cant able to execute the script. here my script below



this script is working only for one suffix domain.

I want to run this script, if x.servera.com not reachable then try x.serverb.com

I have 5k servers with 2 domain alias.


my host list file have the below content
pp1
pp2
pp3
pp4
pp5

those servers have 2 domain alias for R&D purpose

.servera.com
.serverb.com

help me

Last edited by prakash0106; 08-03-2018 at 02:39 AM.
 
Old 08-03-2018, 04:43 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by prakash0106 View Post
really sorry for posting the help on this post. I havnt time to open a new post query.
Maybe not, but for the same you expect us to have the time to solve your problem. Do you think that is reasonable?

You were told a hint for a solution. Did you implement it? And where did it go wrong? And where are you stuck now?

We are not a bureau you submit your wish and get a scripted solution delivered. We are happy to help if you get stuck. But not to do your work.

jlinkels
 
Old 08-03-2018, 06:28 AM   #5
prakash0106
LQ Newbie
 
Registered: Jan 2009
Posts: 15

Original Poster
Rep: Reputation: 1
its not home work, my project requirement. as per environment, allowed to execute the remote command via expect script with bash. . but in this case listed servers are in different suffix domain name. sample below:
pp1.servera.com
pp1.serverb.com

my script working based on giving hostlist file. today I found and need to modify my script to work with short hostname and applying the dns suffix. but I cant able to do. hence I asked help on this portal.
 
Old 08-03-2018, 09:12 PM   #6
Deviathan
Member
 
Registered: Dec 2005
Posts: 52

Rep: Reputation: 18
Honestly you're better off creating a local account on the server you're running this script from and creating some ssh keys to upload those keys to each of the servers you need access to. Then you could use ssh in script without needing to worry about passwords and such.

Expect can be a tricky language to use for something beyond relatively simple things. To make it work well can take time and some level of intricacy, and even then it's not always 100% reliable.
 
Old 08-03-2018, 11:56 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
This is the upteenth thread prakash0106 has camped on with this problem, which is not stated clearly enough for anyone to help...

The main thread is here -- please post any responses there...if you can figure out what they're asking for help with...

Duplicate post reported.

Last edited by scasey; 08-03-2018 at 11:57 PM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Access remotely as user1 and execute command as user2 archieval Programming 3 07-18-2012 06:41 AM
ruby execute commands remotely Dr_Death_UAE Programming 0 08-16-2008 08:47 PM
from Win XP, remotely execute a command on Linux using ssh lothario Linux - Software 3 06-21-2008 05:59 PM
URGENT: How to execute a Linux command remotely alix123 Programming 7 04-06-2006 03:00 AM
Using FTP to execute command line commands remotely steve_2010 Solaris / OpenSolaris 4 02-13-2004 08:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:53 PM.

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