Fdisk in fabric

Standard

One of the issues in Fabric is every command, sudo() or run() is equivalent to a new session. Hence it is difficult to do a fdisk command as you need to have an interaction.

In bash script, you overcome this problem by using a pipe. You put the inputs that you want before the | symbol so bash knows what commands to key in

So how do you translate that into a fabric command? I have been exploring around for months, trying to tinker with different ways of running fdisk. Finally I managed to come up with a working command as shown below:


sudo('echo "g\r\n\
n\r\n\
1\r\n\
%s\r\n\
%s\r\n\
"|fdisk /dev/xvdb' %('\n', '\n'))

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s