Get the output from EXPECT ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the output from EXPECT ?
# 1  
Old 11-23-2006
Get the output from EXPECT ?

I'm using expect script, but don't know how to assign an output to a string variable. Any help ?
Thank you for reading!

PS:
In fact i want to get the out put of expect when run grub-md5-crypt to generate MD5 password for GRUB boot loader.
My code:
Code:
#!/bin/sh
#\
exec expect -f "$0" ${1+"$@"}
set password 123456
set timeout 5
spawn grub-md5-crypt
expect "asspword:"
send "$password\r"
expect "passpword:"
send "$password\r"
expect eof

And i want to assign the MD5-password out put to a string variable in my scriipt to write to a file.
Any ideas?

Last edited by fongthai; 11-23-2006 at 05:26 AM..
# 2  
Old 11-23-2006
are you sure that "exec expect" will invoke the expect processor ?
Why don't you try the script with "which expect" and replace the value at the start of the script ? Also let us know what are the error messages ( if any ).
# 3  
Old 11-23-2006
Hi sysgate,

The script above work fine! No error message. But I want to get it output. In other word, it will generate a MD5 string and I just want to catch that string to a variable or a file.
Like we have echo "Helllo" > output_file.txt.
Can we ?
# 4  
Old 11-24-2006
Why don't you try something like :
Code:
exec grub-md5-crypt your-filename >& md.sum

Let me know if this works, because I don't have the proper machine to test the "grub-md5-crypt" function.
I have in one of my scripts something like :
Code:
set md "md5sum"
#call md5 sum
exec $md my-file >& md.sum
puts "md5sum of my-file generated and stored"

# 5  
Old 11-24-2006
Hi,
it does not work!
grub-md5-crypt is usedn to encrypt a password.
You will be ask for a password, then it outout the MD5 string for you.
This is used for /etc/grub.conf when we enable GRUB boot loader password.

Code:
$ grub-md5-crypt
Password:
Retype password:
$1$0Ek4j1$pG3YRuO7fDb/xZ1ebpbKq.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture output from expect script

Hi I am new to Expect scripting. I have to connect to a remote server and capture the output. Here I need output of " send "list registered\r"" to be stored in a file. but after execution, /tmp/capture.txt is of 0 byte #!/usr/bin/expect spawn ssh abc@10.10.10.10 -p 5022 expect... (2 Replies)
Discussion started by: bns928
2 Replies

2. Shell Programming and Scripting

Expect Script - Not Seeing Output from While Loop

I know something simple is missing here, "log_user 1" is set . . . after this utility opens ${InFile} (handle? for IntInFile) it needs to look for something to appear in the file ${IntInFile} and then send it to the spawned process. Then I am locking the file ${IntInFile} and clearing it out -... (0 Replies)
Discussion started by: JuanMatteo
0 Replies

3. Shell Programming and Scripting

How do I use grep output in an expect script?

Hi, I am using expect to ssh to a remote host and run a program on the remote machine which has a variable runtime. I need to wait until it finishes so I can grab the output file of this program. I am trying to use the output of grep to know when the process finishes. I am trying to capture... (0 Replies)
Discussion started by: vagabond1964
0 Replies

4. Shell Programming and Scripting

Help capturing output of expect script

match_max 500000 set timeout 30 set outcome1 {} set outcome2 {} set inputfile C:\\Users\\Administrator\\Desktop\\inputfile.txt send -i $con "\r"; expect -i $con "Desktop>" { exp_send "type $inputfile \r" } set timeout 30 expect { "Desktop>" { set outcome $expect_out(0,string);}... (3 Replies)
Discussion started by: cityprince143
3 Replies

5. Shell Programming and Scripting

Expect doesn't output the logs

(qemu) migrate -d tcp:192.168.122.1:4444 (qemu) info migrate capabilities: xbzrle: off Migration status: completed total time: 4425 milliseconds downtime: 3 milliseconds transferred ram: 130338 kbytes remaining ram: 0 kbytes total ram: 1057152 kbytes duplicate: 232613 pages normal:... (0 Replies)
Discussion started by: yanglei_fage
0 Replies

6. Shell Programming and Scripting

Expect debug output

Hi! I want to start OO in headless mode via expect - the oo command would be su - root -c "/usr/lib/openoffice/program/soffice -headless -nofirststartwizard -norestore -nolockcheck -nocrashreport -nodefault -accept='socket,host=0.0.0.0,port=8100;urp;StarOffice.Service'" and the expect... (2 Replies)
Discussion started by: senior.weber
2 Replies

7. Shell Programming and Scripting

How can I scroll the terminal output with Expect

Hi, I'm trying to come up with a simple expect script that allows me to login to a system and run a single command ... something like this: #!/usr/bin/expect -f # let's set some variables #set password set ipaddr set ponumber set hostname set timeout -1 # let's now connect to the... (0 Replies)
Discussion started by: danielsf
0 Replies

8. UNIX for Dummies Questions & Answers

how to save the output of command in tcl/expect

hi, everyone: I just wonder how to save the output of command, I mean everything, save as a string into a variable. another question is I try to ls the details of a directory, but it works in the shell, not in the script. for example code: ls -ltr *se100* | grep ^- | tail -1 | awk '... (1 Reply)
Discussion started by: allenxiao7
1 Replies

9. Shell Programming and Scripting

Expect - Interact output hangs when large output

Hello, I have a simple expect script I use to ssh to a workstation. I then pass control over to the user with interact. This script works fine on my HP and Mac, but on my Linux Desktop, I get a problem where the terminal hangs when ever I execute a command in the interact session that requires a... (0 Replies)
Discussion started by: natedog
0 Replies

10. Shell Programming and Scripting

want to use output of c programme in expect

hi i am having a c code which gives the output of my password in text format i.e when i run my c code which which gives the password asfollows====>>>>>> $./passwdprogram ======>>>>>>abc@123(this is the output) now i have an expect script to remotely ssh which uses the password set in ... (0 Replies)
Discussion started by: xander
0 Replies
Login or Register to Ask a Question