Python Forum
search and store a value from linux command output in to variable python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
search and store a value from linux command output in to variable python
Hi I am a python bigginer, I have a scenario where I need to search and select a particular value from linux command "df -h".

dumpe2fs 1.42.13.x5 (23-Mar-2017)
Inode count: 786432000

In this above output I need to store the inode count number in to a variable to use it for further calculation.
Can anyone explain how to use python regular expressions to do the above task?
Get the output using subprocess.

import subprocess

output =['df', '-h'], stdout=subprocess.PIPE).stdout
output = output.decode('utf-8')

for line in output.split('\n'):
    if line.startswith('Inode count:'):
        inode_cnt = int(line.split()[1])
Something like that.
Btw, I don't get the number of inodes with df -h.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python syntax in Linux St0rmcr0w 2 158 Jul-29-2021, 01:40 PM
Last Post: snippsat
  How to input & output parameters from command line argument shantanu97 1 556 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  I want to search a variable for a string D90 lostbit 3 516 Mar-31-2021, 07:14 PM
Last Post: lostbit
  Getting a GET request output text into a variable to work with it. LeoT 2 417 Feb-24-2021, 02:05 PM
Last Post: LeoT
  how to run linux command with multi pipes by python !! evilcode1 2 484 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  where to get portable Python for Linux (Fedora)? python001 5 753 Nov-01-2020, 05:23 PM
Last Post: Larz60+
  Python in Linux environment on RPI kendias 22 5,984 Sep-05-2020, 03:04 AM
Last Post: K_Research
  How does a set in python store the elements? idknuttin 5 992 Jul-10-2020, 10:46 PM
Last Post: Gribouillis
  How do I pick the right python in Linux env? MDRI 9 1,250 Jun-27-2020, 05:40 PM
Last Post: snippsat
  control a linux program with python Fifoux082 9 1,538 May-08-2020, 04:24 PM
Last Post: Fifoux082

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020