Problem in sending inputs to format command using expect | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Problem in sending inputs to format command using expect

Shell Programming and Scripting


Tags
expect script execution problems

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2013
chidori chidori is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 3 December 2013, 12:16 PM EST
Posts: 215
Thanks: 51
Thanked 3 Times in 3 Posts
Problem in sending inputs to format command using expect

Hi ,

I am not able figure out how to use expect tool to send input to this prompt of format


Code:
Searching for disks...done
selecting c0t3d0
[disk formatted]


FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format>

my try

Code:
spawn "format -d c0t3d0"
expect "*format>*"  # I feel something is wrong over here
send "partition/r"

Please help
Sponsored Links
    #2  
Old 03-26-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 20 August 2014, 3:47 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,398
Thanks: 8
Thanked 536 Times in 515 Posts
Is this running over any medium that might add delay, that a line with no linefeed might hang up? Try also expecting the '[disk formatted]' line, as early input will not be lost.
Sponsored Links
    #3  
Old 03-26-2013
chidori chidori is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 3 December 2013, 12:16 PM EST
Posts: 215
Thanks: 51
Thanked 3 Times in 3 Posts
ok , i was able to fix that. btw. can you please let me know how to process pattern that is reptitive . for example

I am setting Free Hog paritition and i have to enter the size of each partition and it would be set to zero. should i create 7 expect function lines and each time send value 0 to it or is there any other way in expect tool ?
    #4  
Old 03-27-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 20 August 2014, 3:47 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,398
Thanks: 8
Thanked 536 Times in 515 Posts
What good is a partition of size zero?

Expect runs in tcl, as I recall, so there may be looping constructs in tcl you can include. The man page does not show and flow of control commands: Man Page for expect (all Section 0) - The UNIX and Linux Forums You could generate the expect script using a shell loop. You can generate it on the fly as a named pipe or with commands from stdin in interactive mode:

The -f flag prefaces a file from which to read commands from. The flag
itself is optional as it is only useful when using the #! notation (see
above), so that other arguments may be supplied on the command line.
(When using Expectk, this option is specified as -file.)

By default, the command file is read into memory and executed in its
entirety. It is occasionally desirable to read files one line at a
time. For example, stdin is read this way. In order to force arbi-
trary files to be handled this way, use the -b flag. (When using
Expectk, this option is specified as -buffer.)Notethatstdio-buffering-
maystilltakeplacehoweverthisshouldn'tcauseproblemswhenreadingfromafi-
foorstdin.

If the string "-" is supplied as a filename, standard input is read
instead. (Use "./-" to read from a file actually named "-".)

The -i flag causes Expect to interactively prompt for commands instead
of reading them from a file. Prompting is terminated via the exit com-
mand or upon EOF. See interpreter (below) for more information. -i is
assumed if neither a command file nor -c is used. (When using Expectk,
this option is specified as -interactive.)

-- may be used to delimit the end of the options. This is useful if
you want to pass an option-like argument to your script without it
being interpreted by Expect. This can usefully be placed in the #!
line to prevent any flag-like interpretation by Expect. For example,
the following will leave the original arguments (including the script
name) in the variable argv.

#!/usr/local/bin/expect --

Note that the usual getopt(3) and execve(2) conventions must be
observed when adding arguments to the #! line.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sending content of a file in Expect alireza6485 Shell Programming and Scripting 1 05-23-2012 07:50 AM
Query on sending inputs to a running application srkelect Shell Programming and Scripting 1 11-20-2009 08:02 AM
Expect: run a command first before sending Tr00tY Shell Programming and Scripting 2 11-19-2009 12:18 PM
Checking the format of inputs in a file sendhilmani123 Shell Programming and Scripting 13 05-19-2006 06:12 PM
Problem with mailx command when sending attachment. miltony Shell Programming and Scripting 2 12-02-2005 11:43 AM



All times are GMT -4. The time now is 03:29 AM.