Expect script to ssh into MMI


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script to ssh into MMI
# 1  
Old 03-11-2009
Expect script to ssh into MMI

Guys,
I know this is tricky.. I'm trying to write a script to pull info from a MMI device.
Following script logins into the server and then changes to super user. Opens MMI session and then exits out. I need to run the command under the MMI session "dsp_alarm_span all" Is there any other way to do this?

Code:
 
#!/usr/bin/env expect -f
set timeout -1
set stty_init -echo
spawn ssh 10.242.112.100 -l loginuser
#match_max 100000
expect "Password:"
send -- "asdfgh\r"
send -- "\r"
expect "loginuser@mcoa:~$ "
send -- "su - root\r"
expect "Password:"
send -- "qwerty\r"
 
expect "root@mcoa:~#"
send -- "/usr/local/bin/mmi_cmd\r"
 
 
expect -exact "MMI>"
 
send -- "dsp_alarm_span all\r"
 
send -- "exit\r"

# 2  
Old 03-11-2009
You can try...
Code:
ssh -l root 10.242.112.100  '/usr/local/bin/mmi_cmd;dsp_alarm_span all'

but ssh will prompt for the password, so you're still in expect territory if you want it fully automated. You can get around this by using public/private keys.
# 3  
Old 03-12-2009
No luck with the above command.

can I atleast automate till loging as root. By the way I can't login directly as root. I need to be loginuser first.

using expect script it exits out
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

2. Shell Programming and Scripting

Expect script ssh passwordless login

how can i use an expect script to do a passwordless ssh login and run a script on a bunch of remote hosts? I do not want to use public key authentication as this would require me to setup the keys on the clients etc.... (2 Replies)
Discussion started by: tdubb123
2 Replies

3. Shell Programming and Scripting

SSH Script is sticking, & sign not doing what I would expect

I am having an issue where I am do an SSH to about 30 servers one at a time however my script is getting hung up sometimes on the SSH. I thought the & at the end as seen below would fire it and move on but that does not seem to be working. #!/bin/s for remsys in trumpetsnail angel delphin... (3 Replies)
Discussion started by: LRoberts
3 Replies

4. Shell Programming and Scripting

expect ssh script cannot finish and exit

All i am new to linux, and try to have a simple expect script to ssh then telnet to the network equipment, and exit itself. but dont know why i hang at the last $ #!/usr/bin/expect set timeout 10 set arg set arg1 spawn ssh -l UserA 1.1.1.1 expect "assword:"; send "PasSwOrD\r";... (1 Reply)
Discussion started by: samoptimus
1 Replies

5. Shell Programming and Scripting

Passing Password to SSH without using expect in a Script

How can I pass password in SSH command without using expect in a shell program. I don't have expect installed on my Solaris server. #!/bin/bash ssh user@hotname (how to supply pass in script?:wall:) Experts please help its very urgent. Shrawan Kumar Sahu (4 Replies)
Discussion started by: ss135r
4 Replies

6. Shell Programming and Scripting

Script using SSH with expect command

Hi all, I want to connect to some host with "ssh". I have googled and got some commands of "expect" and "spawn". I was not aware of these commands and tried below script. $ cat auto.sh set host xx.xx.xx.xx set password abcd@1234 set user root spawn ssh $user@$host expect "*?assword:*"... (4 Replies)
Discussion started by: divya bandipotu
4 Replies

7. Shell Programming and Scripting

ssh is not working while calling through expect shell script

Hi, Please share you experience and way out on below error:--> #!/bin/bash -xv FILE=login.txt + FILE=login.txt CONNECT=sshlogin.exp + CONNECT=sshlogin.exp SERVERNAME=$1 + SERVERNAME=192.168.12.1 MyServer="" + MyServer= MyUser="" + MyUser= MyPassword="" + MyPassword= exec 3<&0 +... (6 Replies)
Discussion started by: manish_1678
6 Replies

8. Shell Programming and Scripting

expect ssh script issue with if and foreach

Hi, I am trying to create an ssh script to login to cisco routers and activate/deactivate bgp neighbors if they match certain conditions. I dont think my "if" and "foreach" are working correctly. Any help is appreciated. Below is my script: ... (0 Replies)
Discussion started by: blahblahsomeone
0 Replies

9. Shell Programming and Scripting

Expect Script to Automate SSH

How would I write an expect script to automate ssh and what file extention do expect files use? (11 Replies)
Discussion started by: Prodiga1
11 Replies

10. Shell Programming and Scripting

SSH Expect Script

Ok, i don't know if anyone else here have had to deal with something like this before, but here's my situation. I have about 1000+ servers I need to log into to do something. What i need to do is to log into each server, go to a certain directory on each of the servers, copy the files that... (3 Replies)
Discussion started by: SkySmart
3 Replies
Login or Register to Ask a Question