ALPHY GEORGE
ALPHY GEORGE

Reputation: 131

Python fabric variable

I am trying to configure a script using fabric and i would like to access python variable in bash command being run using the run () of fabric. Below is the code

    vol_ex=e.run("sudo fdisk -l | grep Disk | awk {'print $2'} | grep -e '/dev/xv*' -e '/dev/sd*' | tr -d ':'")
    vol_ex1=vol_ex.stdout
    print("Vol_ex1=%s" % vol_ex1)
    inst=conn.describe_instances(Filters=[{"Name":"network-interface.association.public-ip", "Values":["ip"]}])
    inst_id=inst["Reservations"][0]["Instances"][0]["InstanceId"]
    print(inst_id)
    inst_az=inst["Reservations"][0]["Instances"][0]["Placement"]["AvailabilityZone"]
    disk=e.run("sudo fdisk -l | grep Disk | grep 'vol_ex1' | awk '{print $3}' | cut -d'.' -f1")

I am trying to get the disk name which is stored in "vol_ex1" but the same cannot be used to get the size in variable "disk". How can we pass python variable to such bash commands?

Upvotes: 0

Views: 85

Answers (1)

ALPHY GEORGE
ALPHY GEORGE

Reputation: 131

i created the command as string into a variable and tried to run it using run() but not working

    vol_ex2="sudo fdisk -l | grep Disk | grep "+vol_ex1+"| awk '{print $3}' | cut -d'.' -f1"
    vol_ex2='uptime'
    disk=e.run(vol_ex2)

I tried printing vol_ex2 and seems the command is valid but unable to execute it using run ().

Can anyone assist with this ?

Upvotes: 0

Related Questions