[Linux][Python]How to assign os.system output to a python variable


#This python script is to get  system’s VGA  monitor info import commands command = “lspci | grep VGA ” status, vgaInfo = commands.getstatusoutput(command) print “VGA info=%s” % ( vgaInfo ) which will give the output VGA info=00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 18) in my system

[Shell Script]How to execute multiple shell commands using a single shell variable ?


To execute multiple shell commands using a single shell variable, Assign the multiple shell commands to a variable. execute the shell variable using echo  eg: Find a.txt in the present directory  Let the multiple commands are ls and grep  Let the shell variable is cmd . cmd=$(ls | grep a.txt ) To execute the commandsContinue reading “[Shell Script]How to execute multiple shell commands using a single shell variable ?”

[Shell Script]How to find the total count of particular string in a file


Lets say the file name is file.txt .  To find the total count of particular string , lets say “abc” , from the file.txt , execute the following command   tr -s ‘ ‘ ‘\n’ < file.txt | grep abc | wc -l    Explanation of the above command  tr -s ‘ ‘ ‘\n’    Continue reading “[Shell Script]How to find the total count of particular string in a file”

[Linux][Shell script] print fibonacci series of 12 numbers


#!/bin/sh# Fibonacci series – eg:- “0 1 1 2 3 5 8 13 21 34 55 …” a=0 #First value of the seriesb=1 #Second value of the series#print the first value of the series.echo $a#print the second value of the series.echo $b#Now a small mathmatics for finding other numbers in the series . for IContinue reading “[Linux][Shell script] print fibonacci series of 12 numbers”

[Shell Script][bash]Finding factorial of a given number using shell script


#!/bin/bash #This script will print the factorial of the number passed as arguement . eg:- ./factorial.sh 4 will print 4! value number=$1 factorial=1 i=$number while [[ $i != 1 && $i != 0 ]] do factorial=`expr $factorial \* $i` i=` expr $i – 1 ` done echo “Factorial of $number is $factorial”

[Linux][Bash]how to export the commands in sbin to PATH variable


Error – ifconfig command is not found !!! lsmod command is not found !!! insmod command is not found !!! list sbin directory content ( ls /sbin). ifconfig will be there . Solution – export PATH=$PATH:/sbin Now try the commands (ifconfig , lsmod or insmod)  …. 🙂 Permanent fix – Add the line export PATH=$PATH:/sbin into .bashrc file in yourContinue reading “[Linux][Bash]how to export the commands in sbin to PATH variable”

[Shell Script][Perl Script]Monitoring a process’s status in a particular time interval


Assuming process.sh is the process which is to be monitored periodically. For checking above process’s health , a script is required . Here statuscheck.sh will check whether the process.sh is running or not. If process is not  running, restart the process using exec command   monitor.sh will call statuscheck.sh in every particular interval(eg: here in everyContinue reading “[Shell Script][Perl Script]Monitoring a process’s status in a particular time interval”