LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   spawn with Expect script (https://www.linuxquestions.org/questions/linux-general-1/spawn-with-expect-script-882407/)

najee1987 05-24-2011 04:29 AM

spawn with Expect script
 
Hi all,

I am trying to create an expect script that will automate ssh login. In ssh first I have to login as ssh user and then su - to login as root. root login using ssh is disabled. I tried spawn one after other but it doesn't work. I want to know is it possible to execute two spawn in an expect script, if then how?.

acid_kewpie 05-24-2011 04:45 AM

you don't want to spawn twice at all. from the expect perspective you are not spawning a new process, you're just reading a stream of characters from ssh and sending other ones back. It has no idea whatsoever what these letters and numbers mean.

Can you not just use a preshared key for this? Whilst root password logins should be disabled, it's not uncommon to still permit shared key logins for root, making this much simpler, and probably removing the need for expect completely.

najee1987 05-24-2011 05:12 AM

Hi,

I agree that using ssh key is safe. But I want that to be done using expect because for one system what I have to do is login to secure user and then login as root user since it is required and for the other one first I have to login to one machine and from that machine I have to ssh login to another machine. What I am trying to do is automate this process using expect script. Please let me know is there a way do that using expect script.

acid_kewpie 05-24-2011 05:19 AM

I already told you there is. You just need to appreciate what expect does and doesn't know about at a process level.

kute 05-24-2011 06:37 AM

If I understand your problem correctly,
you want shell on remote machine for root user.

You do not need to do spawn twice.
You have to spawn as follow

ssh <username>@<server ip> "su"

It will first ask for password for <username>. After receiveing it will execute su command.
Wait for "password:" there and send root password on receiving.
After that drop to interactive mode.

najee1987 05-25-2011 01:53 AM

it worked finally
 
i tried with ssh <username>@<server ip> "su" but i was getting the error standard in must be a tty. But anyway the problem got solved. I wrote some additional line to expect the user prompt and send the commands to terminal rather than try to spawn a process.
Thank you kute for your suggestion


All times are GMT -5. The time now is 07:06 AM.