Sponsored Content
Top Forums Shell Programming and Scripting Using variable as a file name Post 302782719 by twjolson on Tuesday 19th of March 2013 11:16:52 AM
Old 03-19-2013
Here is the output of bash -xv :

Code:
#!/bin/bash -xv

image="$1"
+ image='AD-ACE Recert.E01'

#Create a non-spaced, non-extensioned version of the filename for a folder name.
x="$image"
+ x='AD-ACE Recert.E01'
y=${x%%.*}
+ y='AD-ACE Recert'
iname=`echo ${y} | sed 's/ /_/g'`
echo ${y} | sed 's/ /_/g'
++ echo AD-ACE Recert
++ sed 's/ /_/g'
+ iname=AD-ACE_Recert

#Determine if a folder with the same name as the image file exists, if not create.
if [ -d $iname ]
	then	
		read  -a c -p"$iname folder(s) exists, continuing may overwrite previous data.  Continue? (y/n)"
		if [ $c = n ]
			then
				exit 1
		fi
	else
		echo "folder does not exist, creating"
		mkdir $iname
fi
+ '[' -d AD-ACE_Recert ']'
+ echo 'folder does not exist, creating'
+ mkdir AD-ACE_Recert

#Run MMLS to find empty portions of the disk, and find entries with 'Unallocated' in them.
mmls "$image" | grep Unallocated | while read line
	do
		ssect=`echo $line | awk '{print $3+0}'`
		esect=`echo $line | awk '{print $4+0}'`
		bleng=`echo $line | awk '{print $5*512}'`
		fname=`echo $line | awk '{print "Unallocated-'${ssect}'-'${esect}'"}'`
		ewfexport -f raw -S 0 -o $ssect -B $bleng -t ./$iname/$fname "$image" 2> /dev/null
	done
+ mmls 'AD-ACE Recert.E01'
+ grep Unallocated
+ read line
echo $line | awk '{print $3+0}'
++ echo 01: ----- 0000000000 0000000127 0000000128 Unallocated
++ awk '{print $3+0}'
+ ssect=0
echo $line | awk '{print $4+0}'
++ echo 01: ----- 0000000000 0000000127 0000000128 Unallocated
++ awk '{print $4+0}'
+ esect=127
echo $line | awk '{print $5*512}'
++ echo 01: ----- 0000000000 0000000127 0000000128 Unallocated
++ awk '{print $5*512}'
+ bleng=65536
echo $line | awk '{print "Unallocated-'${ssect}'-'${esect}'"}'
++ echo 01: ----- 0000000000 0000000127 0000000128 Unallocated
++ awk '{print "Unallocated-0-127"}'
+ fname=Unallocated-0-127
+ ewfexport -f raw -S 0 -o 0 -B 65536 -t ./AD-ACE_Recert/Unallocated-0-127 'AD-ACE Recert.E01'
+ read line
echo $line | awk '{print $3+0}'
++ echo 05: ----- 0000497792 0000501758 0000003967 Unallocated
++ awk '{print $3+0}'
+ ssect=497792
echo $line | awk '{print $4+0}'
++ echo 05: ----- 0000497792 0000501758 0000003967 Unallocated
++ awk '{print $4+0}'
+ esect=501758
echo $line | awk '{print $5*512}'
++ echo 05: ----- 0000497792 0000501758 0000003967 Unallocated
++ awk '{print $5*512}'
+ bleng=2031104
echo $line | awk '{print "Unallocated-'${ssect}'-'${esect}'"}'
++ echo 05: ----- 0000497792 0000501758 0000003967 Unallocated
++ awk '{print "Unallocated-497792-501758"}'
+ fname=Unallocated-497792-501758
+ ewfexport -f raw -S 0 -o 497792 -B 2031104 -t ./AD-ACE_Recert/Unallocated-497792-501758 'AD-ACE Recert.E01'
+ read line

#Determine if a file is empty or contains data.
echo "Results of sum command against all generated raw files" > $iname-sumresults.txt
+ echo 'Results of sum command against all generated raw files'
sum ./$iname/Unallocated*.raw >> $iname-sumresults.txt
+ sum ./AD-ACE_Recert/Unallocated-0-127.raw ./AD-ACE_Recert/Unallocated-497792-501758.raw
sum ./$iname/Unallocated*.raw | while read line
	do
		if [ `echo $line | awk '{print $1}'` = 00000 ]
			then
				echo $line | awk '{print $3 " is empty, disregarding."}'

			else
				echo $line | awk '{print $3 " is not empty.  Creating XXD report"}'
				opxxd=`echo $line | awk '{print $3}'`		
				xxd -a > $opxxd.txt
		fi
	done
+ sum ./AD-ACE_Recert/Unallocated-0-127.raw ./AD-ACE_Recert/Unallocated-497792-501758.raw
+ read line
echo $line | awk '{print $1}'
++ echo 16715 64 ./AD-ACE_Recert/Unallocated-0-127.raw
++ awk '{print $1}'
+ '[' 16715 = 00000 ']'
+ echo 16715 64 ./AD-ACE_Recert/Unallocated-0-127.raw
+ awk '{print $3 " is not empty.  Creating XXD report"}'
echo $line | awk '{print $3}'
++ echo 16715 64 ./AD-ACE_Recert/Unallocated-0-127.raw
++ awk '{print $3}'
+ opxxd=./AD-ACE_Recert/Unallocated-0-127.raw
+ xxd -a
+ read line

Thanks for the extra info. That will make my code a little leaner, if I ever get this script working...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

2. Shell Programming and Scripting

Split variable length and variable format CSV file

Dear all, I have basic knowledge of Unix script and her I am trying to process variable length and variable format CSV file. The file length will depend on the numbers of Earnings/Deductions/Direct Deposits. And The format will depend on whether it is Earnings/Deductions or Direct Deposits... (2 Replies)
Discussion started by: chechun
2 Replies

3. Shell Programming and Scripting

variable within a variable from file

script below sets variable "var". Then sets "var2" (which contains "var" whithin it, see test.config file) from config file. test.sh ---------------------------- #!/bin/sh var="varvalue" while read line do var2=${line} done <./test.config echo "var value is: $var" echo... (2 Replies)
Discussion started by: bcnjc
2 Replies

4. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

5. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

6. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

7. Shell Programming and Scripting

Two question: remove from the other variable or file to get another variable or file

Question 1: A="a b c d e f g 1 2 3 4 5" B="c 3" get C="a b d e f g 1 2 4 5" Question 2: cat file1 a b c (6 Replies)
Discussion started by: yanglei_fage
6 Replies

8. Shell Programming and Scripting

To print value for a $variable inside a $variable or file

Hi guys, I have a file "abc.dat" in below format: FILE_PATH||||$F_PATH TABLE_LIST||||a|b|c SYST_NM||||${SRC_SYST} Now I am trying to read the above file and want to print the value for above dollar variables F_PATH and SRC_SYST. The problem is it's reading the dollar variables as... (5 Replies)
Discussion started by: abcabc1103
5 Replies

9. Shell Programming and Scripting

Calling a variable of variable from a file

Hi All, I have file which have looks like below abc=${def} def=${efg} efg= "this is the actual value" based on "abc" value I have to call "efg" value , Am using below lines but it is not working #!/bin/bash source file.txt echo $abc Please wrap all code, files, input &... (5 Replies)
Discussion started by: Prashanth.K
5 Replies

10. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies
ECHO(3) 								 1								   ECHO(3)

echo - Output one or more strings

SYNOPSIS
void echo (string $arg1, [string $...]) DESCRIPTION
Outputs all parameters. echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses. echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syn- tax only works with the short_open_tag configuration setting enabled. I have <?=$foo?> foo. PARAMETERS
o $arg1 - The parameter to output. o $... - RETURN VALUES
No value is returned. EXAMPLES
Example #1 echo examples <?php echo "Hello World"; echo "This spans multiple lines. The newlines will be output as well"; echo "This spans multiple lines. The newlines will be output as well."; echo "Escaping characters is done "Like this"."; // You can use variables inside of an echo statement $foo = "foobar"; $bar = "barbaz"; echo "foo is $foo"; // foo is foobar // You can also use arrays $baz = array("value" => "foo"); echo "this is {$baz['value']} !"; // this is foo ! // Using single quotes will print the variable name, not the value echo 'foo is $foo'; // foo is $foo // If you are not using any other characters, you can just echo variables echo $foo; // foobar echo $foo,$bar; // foobarbarbaz // Some people prefer passing multiple parameters to echo over concatenation. echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10); echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . " "; echo <<<END This uses the "here document" syntax to output multiple lines with $variable interpolation. Note that the here document terminator must appear on a line with just a semicolon. no extra whitespace! END; // Because echo does not behave like a function, the following code is invalid. ($some_var) ? echo 'true' : echo 'false'; // However, the following examples will work: ($some_var) ? print 'true' : print 'false'; // print is also a construct, but // it behaves like a function, so // it may be used in this context. echo $some_var ? 'true': 'false'; // changing the statement around ?> NOTES
Note Because this is a language construct and not a function, it cannot be called using variable functions. SEE ALSO
print(3), printf(3), flush(3), Heredoc syntax. PHP Documentation Group ECHO(3)
All times are GMT -4. The time now is 03:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy