Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
So the result I expect in "chkselinux" is either "1" (if selinux is on), or something else (usually "cat /selinux/enforce: file not found"). However, what actually goes in the variable is all the output of the spawn directive, plus the output of the ssh command embedded in the middle.
Of course, if I can set up host keys, I can just run an ssh command from the bash script, but that is not an option in this environment.
Interact may work, but how do I tell the bash script to end the expect script?
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Because you embedded the call of the expect script in ``, all the output of the expect script goes into the variable chkselinux.
Expect echoes all output to stdout, and that is what is put as result from calling in ``
(Just a tip, use $(...) instead of `...`. It is equal, but is avoids reading mistakes)
What answer do you actually expect from your expect script (no pun intended). Should it tell you whether your login was succesful? How does that fit with the output of "cat /selinux/enforce"? Where do the variables $user, $password etc get their values from in the expect script?
I am trying to help, but I might be more succesful if I understand what you try to achieve.
Thanks for your reply - the user, password, and hostname arguments are provided by the bash script that calls the expect script, and it reads them from a file. That part of the script works - it logs in as expected and runs the desired commands. I just want to capture ONLY the output from the command, not the entire login process.
I tried using a log_file argument, but that also only captures the login process and not the single command I want to run.
Basically, I want to be able to do the same thing as ssh, assuming one has installed one's id_dsa.pub key in the server's .ssh/authorized_keys file:
output_var=$(ssh user@host "some_command")
But do it with an expect session.
BTW I know about the $() construct, but the script was written by my boss, and I don't want to throw him off
Thanks for the code suggestion, I may try that out - I did end up re-writing the code to just use ssh commands with installed authorized_keys, though with the number of servers we have, I need to use expect to copy the keys up the the various servers first.