LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 05:29 AM   #1
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

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, 05:34 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

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

var=`cmd`
echo $var
 
Old 11-17-2008, 05:37 AM   #3
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

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, 12:59 AM   #4
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

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 07:50 AM.
 
  


Reply



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 06:23 AM
Running command in gnome-terminal from script results in "...error creating child..." PlancksCnst Linux - General 6 04-08-2009 12:09 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
"Successful install" results in "Boot device not found" slackr007 Fedora 2 06-21-2005 04:05 PM
"Successful install" results in "Boot device not found" slackr007 Linux - Newbie 2 05-31-2005 08:02 PM

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

All times are GMT -5. The time now is 05:55 PM.

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
Open Source Consulting | Domain Registration