problem in automating "fdisk" command using send and expect


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in automating "fdisk" command using send and expect
# 1  
Old 08-07-2012
CPU & Memory problem in automating "fdisk" command using send and expect

hi
i want to automate fdisk command .
i spawned a process containing fdisk command from a process
and tried to send the options to fdisk promt from that process.
but that spawed process is notstarting itself


help me out

trying for two days
Smilie

my code:
Code:
#!/bin/bash
echo starting in send
cat <<EOF > /root/test_ntp/send1
#!/usr/bin/expect -f
spawn sh spawn_process
send -- "m\n"
send -- "l\n"
send -- "q\n"
EOF
chmod 755 send1
./send1
rc=$?
if [ $rc -ne 0 ]
then
  echo failed
else
  echo passed
fi
echo done in send


Last edited by Franklin52; 08-07-2012 at 06:53 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 08-07-2012
I don't know what you're trying to accomplish, but I don't see fdisk anywhere in your code.
# 3  
Old 08-07-2012
fdisk is in separate file

thats the spawned process spawn_process


code for that spawn_process


Code:
#!/bin/bash
fdisk /dev/xvdj

Smilie

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 08-07-2012 at 11:18 AM..
# 4  
Old 08-08-2012
OK, I did some test and here's the conclusion:

If you spwan a process in Expect and don't literally "expect" the process's output but "send" command immediately, Expect will send command *before* the process even ready to accept inputs. Thus a better way is to actually "expect" something before "send":
Code:
expect "m for help" {
    send "m\n"
}
expect "m for help" {
    send "l\n"
}
expect "m for help" {
    send "q\n"
}

Good luck.
This User Gave Thanks to leafei For This Post:
# 5  
Old 08-08-2012
Expect script is useless here, just perform your tasks through the pure shell script
An example
Code:
echo "n
p
1


w" | fdisk /dev/sdb

just modify the parameters to suit your requirements
This User Gave Thanks to complex.invoke For This Post:
# 6  
Old 08-08-2012
thanks to both of you.It worked. Smilie

---------- Post updated at 01:24 AM ---------- Previous update was at 01:21 AM ----------

thanks to every one

another way of doing this
Code:
fdisk "device to be partitioned" <<EOF
n
p
1

w
EOF


Last edited by Franklin52; 08-08-2012 at 05:10 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Expect Scripting - Using the "interact" command?

Hello All, I am writing an Expect Script to execute some commands over ssh then exit the script. The script works just fine if I automate everything and assuming the correct password was entered. So this Expect Script gets executed from a Bash script... From the Bash script I pass along an... (0 Replies)
Discussion started by: mrm5102
0 Replies

4. Shell Programming and Scripting

exec perl in expect script yields "invalid command"

I'm trying to execute something like this: exec perl -i -pe 's/\015/\012/g' '${file}' in my expect script and I get: error "invalid command name \"perl\". however, if I run perl -i -pe 's/\015/\012/g' "/Users/Shared/menu-items.txt" directly in my terminal, it runs fine. I'm an... (4 Replies)
Discussion started by: dpouliot
4 Replies

5. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

question about "sleep" command in expect script

I wrote some expect script to telnet to some device to execute some commands.Firstly,I can't get full result some time,then I try to add some "sleep" command in it.Fortunately it works. My idea about it is that it uses sleep command to wait the result to be displayed.Am I right or correct the... (4 Replies)
Discussion started by: robbiezr
4 Replies

8. UNIX for Dummies Questions & Answers

How to send multiple attachment through "nail" command

Hi, I using the "nail" command to send an attachement,the command is : nail -s TEST -a $param/Result.html xyz@yahoo.com </dev/null but now my requirement is changed, I have to send two attachments,through the same mail.. :rolleyes: I have tried this: nail -s TEST -a $param/*.html... (1 Reply)
Discussion started by: Amey Joshi
1 Replies

9. Shell Programming and Scripting

Need Help on "Expect" command in shell programming

Hi, Iam using Solaris 10 OS in the server.iam unable to find expect command in bin directory.how can i install the script in the server to use "expect" in shell programming. (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

10. UNIX for Dummies Questions & Answers

Unix "at" / "Cron" Command New Problem...Need help

Hi All, I am trying to schedule a one time job using the at command with the help of shell script for my project. The shell script should take a parameter as a command line argument from the at command itself. Is it possible to take a command line parameter for a shell script in the command... (3 Replies)
Discussion started by: Mohanraj
3 Replies
Login or Register to Ask a Question