Expect script + automated telnet process between three Linux machines
Is it possible to do the following by expect script?
I have Linux server that connected to linux_machine1 and linux_machine1 connected to linux_machine2
My Linux server have access only to linux_machine1 ( linux server can telnet to linux_machine1 but can’t telnet to linux_machine2 )
But from linux_machine1 I have access VIA telnet to linux_machine2
So my question is:
I need to develop expect script that perform telnet from the Linux server to linux_machine1
then expect will perform telnet to linux_machine2 from linux_machine1 and will copy the /etc/hosts file from linux_machine2 to my Linux server
Is this scenario can be implemented by expect script?
Short example that descript the process:
( run expect from Linux server ) --> linux_machine1 --> linux_machine2
Linux server <-- /etc/hosts from linux_machine2 <--
- remark - expect script need to be activate from the linux server
linux expect telnet autologin
add a comment |
Is it possible to do the following by expect script?
I have Linux server that connected to linux_machine1 and linux_machine1 connected to linux_machine2
My Linux server have access only to linux_machine1 ( linux server can telnet to linux_machine1 but can’t telnet to linux_machine2 )
But from linux_machine1 I have access VIA telnet to linux_machine2
So my question is:
I need to develop expect script that perform telnet from the Linux server to linux_machine1
then expect will perform telnet to linux_machine2 from linux_machine1 and will copy the /etc/hosts file from linux_machine2 to my Linux server
Is this scenario can be implemented by expect script?
Short example that descript the process:
( run expect from Linux server ) --> linux_machine1 --> linux_machine2
Linux server <-- /etc/hosts from linux_machine2 <--
- remark - expect script need to be activate from the linux server
linux expect telnet autologin
I guess you already know telnet is insecure and don't know if you can switch to ssh, which is more secure and solves your problem. If you are able to switch to ssh you can create a tunnel and access machine 2 through machine 1 from your linux box with just one simple ssh command (I think the parameter you need is -J).
– YoMismo
Jan 11 at 12:19
add a comment |
Is it possible to do the following by expect script?
I have Linux server that connected to linux_machine1 and linux_machine1 connected to linux_machine2
My Linux server have access only to linux_machine1 ( linux server can telnet to linux_machine1 but can’t telnet to linux_machine2 )
But from linux_machine1 I have access VIA telnet to linux_machine2
So my question is:
I need to develop expect script that perform telnet from the Linux server to linux_machine1
then expect will perform telnet to linux_machine2 from linux_machine1 and will copy the /etc/hosts file from linux_machine2 to my Linux server
Is this scenario can be implemented by expect script?
Short example that descript the process:
( run expect from Linux server ) --> linux_machine1 --> linux_machine2
Linux server <-- /etc/hosts from linux_machine2 <--
- remark - expect script need to be activate from the linux server
linux expect telnet autologin
Is it possible to do the following by expect script?
I have Linux server that connected to linux_machine1 and linux_machine1 connected to linux_machine2
My Linux server have access only to linux_machine1 ( linux server can telnet to linux_machine1 but can’t telnet to linux_machine2 )
But from linux_machine1 I have access VIA telnet to linux_machine2
So my question is:
I need to develop expect script that perform telnet from the Linux server to linux_machine1
then expect will perform telnet to linux_machine2 from linux_machine1 and will copy the /etc/hosts file from linux_machine2 to my Linux server
Is this scenario can be implemented by expect script?
Short example that descript the process:
( run expect from Linux server ) --> linux_machine1 --> linux_machine2
Linux server <-- /etc/hosts from linux_machine2 <--
- remark - expect script need to be activate from the linux server
linux expect telnet autologin
linux expect telnet autologin
edited Apr 29 '14 at 1:57
asked Apr 29 '14 at 1:47
user58412
I guess you already know telnet is insecure and don't know if you can switch to ssh, which is more secure and solves your problem. If you are able to switch to ssh you can create a tunnel and access machine 2 through machine 1 from your linux box with just one simple ssh command (I think the parameter you need is -J).
– YoMismo
Jan 11 at 12:19
add a comment |
I guess you already know telnet is insecure and don't know if you can switch to ssh, which is more secure and solves your problem. If you are able to switch to ssh you can create a tunnel and access machine 2 through machine 1 from your linux box with just one simple ssh command (I think the parameter you need is -J).
– YoMismo
Jan 11 at 12:19
I guess you already know telnet is insecure and don't know if you can switch to ssh, which is more secure and solves your problem. If you are able to switch to ssh you can create a tunnel and access machine 2 through machine 1 from your linux box with just one simple ssh command (I think the parameter you need is -J).
– YoMismo
Jan 11 at 12:19
I guess you already know telnet is insecure and don't know if you can switch to ssh, which is more secure and solves your problem. If you are able to switch to ssh you can create a tunnel and access machine 2 through machine 1 from your linux box with just one simple ssh command (I think the parameter you need is -J).
– YoMismo
Jan 11 at 12:19
add a comment |
1 Answer
1
active
oldest
votes
From Linux_Server, run the below script.
Don't use telnet
as it is unencrypted. You can rather use ssh
and sftp
as below.
#This part connects to Machine1
#Just change username, password_here and Linux_machine1 to suit your requirement.
#!/usr/bin/expect -f
spawn telnet -l username linux_machine1
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
#Now we are connected to Linux_Machine1 from where we will connect to Linux_machine2
#Just change username, password_here and Linux_machine2 to suit your requirement.
spawn ftp username@machine2
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
expect "ftp>"
send -- "get /etc/hostsr"
expect "ftp>"
send "quit r"
In your local folder of Linux_Server, a copy of /etc/hosts
will be present.
P.S: Tested in local machine and works perfectly fine. If you still wish to use telnet, the above script will give you an idea on how to do it. You can modify the ssh and sftp connections to telnet as you desire.
P.P.S: I would really appreciate if you respond back with either bricks or compliments as I had spent good half an hour in preparing this script :) Ok, not half an hour, but definitely 15 minutes :)
I have a problem with your solution - linux_machine1/2 not have ssh , only telnet because they are very old linux machine , could you advice how to fit your script for telnet ? ( remark I cant install ssh on the ,machines )
– user58412
Apr 29 '14 at 4:17
can I replace the ssh with telnet ?
– user58412
Apr 29 '14 at 4:28
I have made some changes. However, I could not test it as I do not have telnet in my server. Let me know how it goes.
– Ramesh
Apr 29 '14 at 4:28
ok I need to test it on my machine it will take time because I need to drive to my work , lets say 2 hours and I will give you feedbake
– user58412
Apr 29 '14 at 4:29
Sure. It is night for me here. If there is more issues, I will look into it tomorrow. Good night :)
– Ramesh
Apr 29 '14 at 4:30
|
show 1 more comment
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f127008%2fexpect-script-automated-telnet-process-between-three-linux-machines%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From Linux_Server, run the below script.
Don't use telnet
as it is unencrypted. You can rather use ssh
and sftp
as below.
#This part connects to Machine1
#Just change username, password_here and Linux_machine1 to suit your requirement.
#!/usr/bin/expect -f
spawn telnet -l username linux_machine1
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
#Now we are connected to Linux_Machine1 from where we will connect to Linux_machine2
#Just change username, password_here and Linux_machine2 to suit your requirement.
spawn ftp username@machine2
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
expect "ftp>"
send -- "get /etc/hostsr"
expect "ftp>"
send "quit r"
In your local folder of Linux_Server, a copy of /etc/hosts
will be present.
P.S: Tested in local machine and works perfectly fine. If you still wish to use telnet, the above script will give you an idea on how to do it. You can modify the ssh and sftp connections to telnet as you desire.
P.P.S: I would really appreciate if you respond back with either bricks or compliments as I had spent good half an hour in preparing this script :) Ok, not half an hour, but definitely 15 minutes :)
I have a problem with your solution - linux_machine1/2 not have ssh , only telnet because they are very old linux machine , could you advice how to fit your script for telnet ? ( remark I cant install ssh on the ,machines )
– user58412
Apr 29 '14 at 4:17
can I replace the ssh with telnet ?
– user58412
Apr 29 '14 at 4:28
I have made some changes. However, I could not test it as I do not have telnet in my server. Let me know how it goes.
– Ramesh
Apr 29 '14 at 4:28
ok I need to test it on my machine it will take time because I need to drive to my work , lets say 2 hours and I will give you feedbake
– user58412
Apr 29 '14 at 4:29
Sure. It is night for me here. If there is more issues, I will look into it tomorrow. Good night :)
– Ramesh
Apr 29 '14 at 4:30
|
show 1 more comment
From Linux_Server, run the below script.
Don't use telnet
as it is unencrypted. You can rather use ssh
and sftp
as below.
#This part connects to Machine1
#Just change username, password_here and Linux_machine1 to suit your requirement.
#!/usr/bin/expect -f
spawn telnet -l username linux_machine1
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
#Now we are connected to Linux_Machine1 from where we will connect to Linux_machine2
#Just change username, password_here and Linux_machine2 to suit your requirement.
spawn ftp username@machine2
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
expect "ftp>"
send -- "get /etc/hostsr"
expect "ftp>"
send "quit r"
In your local folder of Linux_Server, a copy of /etc/hosts
will be present.
P.S: Tested in local machine and works perfectly fine. If you still wish to use telnet, the above script will give you an idea on how to do it. You can modify the ssh and sftp connections to telnet as you desire.
P.P.S: I would really appreciate if you respond back with either bricks or compliments as I had spent good half an hour in preparing this script :) Ok, not half an hour, but definitely 15 minutes :)
I have a problem with your solution - linux_machine1/2 not have ssh , only telnet because they are very old linux machine , could you advice how to fit your script for telnet ? ( remark I cant install ssh on the ,machines )
– user58412
Apr 29 '14 at 4:17
can I replace the ssh with telnet ?
– user58412
Apr 29 '14 at 4:28
I have made some changes. However, I could not test it as I do not have telnet in my server. Let me know how it goes.
– Ramesh
Apr 29 '14 at 4:28
ok I need to test it on my machine it will take time because I need to drive to my work , lets say 2 hours and I will give you feedbake
– user58412
Apr 29 '14 at 4:29
Sure. It is night for me here. If there is more issues, I will look into it tomorrow. Good night :)
– Ramesh
Apr 29 '14 at 4:30
|
show 1 more comment
From Linux_Server, run the below script.
Don't use telnet
as it is unencrypted. You can rather use ssh
and sftp
as below.
#This part connects to Machine1
#Just change username, password_here and Linux_machine1 to suit your requirement.
#!/usr/bin/expect -f
spawn telnet -l username linux_machine1
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
#Now we are connected to Linux_Machine1 from where we will connect to Linux_machine2
#Just change username, password_here and Linux_machine2 to suit your requirement.
spawn ftp username@machine2
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
expect "ftp>"
send -- "get /etc/hostsr"
expect "ftp>"
send "quit r"
In your local folder of Linux_Server, a copy of /etc/hosts
will be present.
P.S: Tested in local machine and works perfectly fine. If you still wish to use telnet, the above script will give you an idea on how to do it. You can modify the ssh and sftp connections to telnet as you desire.
P.P.S: I would really appreciate if you respond back with either bricks or compliments as I had spent good half an hour in preparing this script :) Ok, not half an hour, but definitely 15 minutes :)
From Linux_Server, run the below script.
Don't use telnet
as it is unencrypted. You can rather use ssh
and sftp
as below.
#This part connects to Machine1
#Just change username, password_here and Linux_machine1 to suit your requirement.
#!/usr/bin/expect -f
spawn telnet -l username linux_machine1
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
#Now we are connected to Linux_Machine1 from where we will connect to Linux_machine2
#Just change username, password_here and Linux_machine2 to suit your requirement.
spawn ftp username@machine2
expect "*?assword:*"
send -- "password_herer"
send -- "r"
expect eof
expect "ftp>"
send -- "get /etc/hostsr"
expect "ftp>"
send "quit r"
In your local folder of Linux_Server, a copy of /etc/hosts
will be present.
P.S: Tested in local machine and works perfectly fine. If you still wish to use telnet, the above script will give you an idea on how to do it. You can modify the ssh and sftp connections to telnet as you desire.
P.P.S: I would really appreciate if you respond back with either bricks or compliments as I had spent good half an hour in preparing this script :) Ok, not half an hour, but definitely 15 minutes :)
edited Apr 29 '14 at 4:27
answered Apr 29 '14 at 3:52
RameshRamesh
23.3k32101182
23.3k32101182
I have a problem with your solution - linux_machine1/2 not have ssh , only telnet because they are very old linux machine , could you advice how to fit your script for telnet ? ( remark I cant install ssh on the ,machines )
– user58412
Apr 29 '14 at 4:17
can I replace the ssh with telnet ?
– user58412
Apr 29 '14 at 4:28
I have made some changes. However, I could not test it as I do not have telnet in my server. Let me know how it goes.
– Ramesh
Apr 29 '14 at 4:28
ok I need to test it on my machine it will take time because I need to drive to my work , lets say 2 hours and I will give you feedbake
– user58412
Apr 29 '14 at 4:29
Sure. It is night for me here. If there is more issues, I will look into it tomorrow. Good night :)
– Ramesh
Apr 29 '14 at 4:30
|
show 1 more comment
I have a problem with your solution - linux_machine1/2 not have ssh , only telnet because they are very old linux machine , could you advice how to fit your script for telnet ? ( remark I cant install ssh on the ,machines )
– user58412
Apr 29 '14 at 4:17
can I replace the ssh with telnet ?
– user58412
Apr 29 '14 at 4:28
I have made some changes. However, I could not test it as I do not have telnet in my server. Let me know how it goes.
– Ramesh
Apr 29 '14 at 4:28
ok I need to test it on my machine it will take time because I need to drive to my work , lets say 2 hours and I will give you feedbake
– user58412
Apr 29 '14 at 4:29
Sure. It is night for me here. If there is more issues, I will look into it tomorrow. Good night :)
– Ramesh
Apr 29 '14 at 4:30
I have a problem with your solution - linux_machine1/2 not have ssh , only telnet because they are very old linux machine , could you advice how to fit your script for telnet ? ( remark I cant install ssh on the ,machines )
– user58412
Apr 29 '14 at 4:17
I have a problem with your solution - linux_machine1/2 not have ssh , only telnet because they are very old linux machine , could you advice how to fit your script for telnet ? ( remark I cant install ssh on the ,machines )
– user58412
Apr 29 '14 at 4:17
can I replace the ssh with telnet ?
– user58412
Apr 29 '14 at 4:28
can I replace the ssh with telnet ?
– user58412
Apr 29 '14 at 4:28
I have made some changes. However, I could not test it as I do not have telnet in my server. Let me know how it goes.
– Ramesh
Apr 29 '14 at 4:28
I have made some changes. However, I could not test it as I do not have telnet in my server. Let me know how it goes.
– Ramesh
Apr 29 '14 at 4:28
ok I need to test it on my machine it will take time because I need to drive to my work , lets say 2 hours and I will give you feedbake
– user58412
Apr 29 '14 at 4:29
ok I need to test it on my machine it will take time because I need to drive to my work , lets say 2 hours and I will give you feedbake
– user58412
Apr 29 '14 at 4:29
Sure. It is night for me here. If there is more issues, I will look into it tomorrow. Good night :)
– Ramesh
Apr 29 '14 at 4:30
Sure. It is night for me here. If there is more issues, I will look into it tomorrow. Good night :)
– Ramesh
Apr 29 '14 at 4:30
|
show 1 more comment
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f127008%2fexpect-script-automated-telnet-process-between-three-linux-machines%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I guess you already know telnet is insecure and don't know if you can switch to ssh, which is more secure and solves your problem. If you are able to switch to ssh you can create a tunnel and access machine 2 through machine 1 from your linux box with just one simple ssh command (I think the parameter you need is -J).
– YoMismo
Jan 11 at 12:19