ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Basically I need to telnet login to a machine, then run some commands. I've sorted the login bit, and this works: (the following is a new file that is called into an existing script)
The interact I don't want there, I want to send it a command to mount a filesystem, however when I put anything other than mount the script just ends and continues running the other script that called the expect script...
Not sure what I'm missing.
Heres pseudo for what I need to happen:
Code:
Send Username
Send Password
cd /root/test
mount machine2:/root/test /root/test
close script and continue with the original script that called it
Basically I need to telnet login to a machine, then run some commands. I've sorted the login bit, and this works: (the following is a new file that is called into an existing script)
The interact I don't want there, I want to send it a command to mount a filesystem, however when I put anything other than mount the script just ends and continues running the other script that called the expect script...
Not sure what I'm missing.
Heres pseudo for what I need to happen:
Code:
Send Username
Send Password
cd /root/test
mount machine2:/root/test /root/test
close script and continue with the original script that called it
Hope that makes some sense.
Yes, but a couple of things stand out. First, and I'm sure you'll get LOTS of feedback about this...you're logging in as ROOT via TELNET??? That is horribly unsafe...telnet sends the password in clear-text, over the network, and it's trivial to catch it. I'd strongly suggest using SSH. Also, I'd disable root logins over the network, for ANY protocol. You can always use "sudo" or even "su" to get root privileges, but login as root is always frowned upon.
Don't know how you're calling your mount statement, but are you putting it in as
Code:
send "mount <device> <path>"
It should just be as if you were entering any other command. An alternative would be to make a small shell-script on the remote box, that contains just the mount statement, and call that script via expect. I'd also look into doing this via Perl, since it has modules specifically written to handle telnet and SSH logins, but that may not be in your comfort zone.
No, im designing the system on a private network before putting it public. Using root just for the sake of permissions. Will be changing it to a user with SU before it goes anywhere public.
Yeah, thats how I'm sending the command, but it freezes after entering the password.
If I put the interact command after the send "password\r" it allows me to continue 'interacting' with the telnet session, however if i try to send another command it just stalls and ends the script.
No, im designing the system on a private network before putting it public. Using root just for the sake of permissions. Will be changing it to a user with SU before it goes anywhere public.
Still, TBOne's advice about ssh is probably the best one you can get at this point. IMO it's better to start in a safe way and further develop it from there than to start it in an unsecure way and worry about security later on.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.