LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-17-2008, 06:29 AM   #1
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,260

Rep: Reputation: Disabled
Script: how to assign values to variables using "awk" results?


I want to write a script to find out the journal size of an ext3 file system. I have two commands (graciously provided by unSpawn):
Code:
The journal is located at inode: 
'tune2fs -l /dev/device | awk '/Journal inode/ {print $3}''

The size is:
debugfs -R "stat <inodenumber>" /dev/device 2>&1| awk '/Size: / {print $6}'|head -1
These commands work okay from the command line. I wanted to do something like
Code:
#!/bin/bash
#first parameter is the device name [s|h]dxy
 
inode='tune2fs -l /dev/device | awk '/Journal inode/ {print $3}''
#and noticed that that won't work.
# nor will
echo "Journal Size: "
debugfs -R "stat <inode>" /dev/$1 2>&1| awk '/Size: / {print $6}'|head -1 >1
Hm. So how can I get the value awk is printing in the first statement loaded into a variable (e.g. inode), and how would the second command print the journal size to the screen?

http://www.tldp.org/LDP/Bash-Beginne...e.html#chap_03 left me stumped...
 
Old 11-17-2008, 06:34 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,700

Rep: Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494
Use backquotes(`) not single quotes(') to run a cmd and save the result thus:

var=`cmd`
echo $var
 
Old 11-17-2008, 06:37 AM   #3
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,260

Original Poster
Rep: Reputation: Disabled
Aha. I'll try that this evening and be back with the result.

Anybody about why printing the results from within the script doesn't work? Can it be done less clumsily?
 
Old 11-18-2008, 01:59 AM   #4
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,260

Original Poster
Rep: Reputation: Disabled
Yep, works. After some thought, I even remembered why , thanks chrism01.

I solved the other question by the same method, i.e. put the statement in back ticks and assigned the value to a variable (yes, I know I could put them out with "echo" but later on I want to calculate the byte value into MBs, so...).

Last edited by JZL240I-U; 11-24-2008 at 08:50 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 07:23 AM
Running command in gnome-terminal from script results in "...error creating child..." PlancksCnst Linux - General 6 04-08-2009 01:09 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 11:47 AM
"Successful install" results in "Boot device not found" slackr007 Fedora 2 06-21-2005 05:05 PM
"Successful install" results in "Boot device not found" slackr007 Linux - Newbie 2 05-31-2005 09:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration