Sponsored Content
Top Forums Shell Programming and Scripting Problem assigning cmd output to variable then using in IF statement Post 302555339 by dqrgk0 on Wednesday 14th of September 2011 12:56:18 PM
Old 09-14-2011
Corona688,

Thanks! That got the variable to take. I think that takes care of #1.

Can you help shed light on #2 and #3? I'm going to see what I can try (again) to make it work...

This is the error I received while trying to run the updated code. I know it has to do with the value in the $FSIZE because du -b outputs the file bytes and the (path)/name of the file.

Code:
 
+ EXISTINGFILE=/test/inbound/finaltickets.csv
++ du -b /test/inbound/finaltickets.csv
+ size1='364    /test/inbound/finaltickets.csv'
+ FSIZE='364    /test/inbound/finaltickets.csv'
+ echo 364 /test/inbound/finaltickets.csv
364 /test/inbound/finaltickets.csv
+ '[' 364 /test/inbound/finaltickets.csv -lt 220 ']'
/test/inbound/./test_wip.sh: line 10: [: too many arguments
+ [[ -s /test/inbound/finaltickets.csv ]]

---------- Post updated at 11:56 AM ---------- Previous update was at 11:46 AM ----------

I guess my challenge with #2 is that I want to always extract only the bytes info (numbers) from the du -b [file] output, but that value can vary in length. Substringing only the byte data is important since I'll be using $FSIZE in the first IF clause...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies

2. Shell Programming and Scripting

Assigning output of command to a variable in shell

hi, I want to assign find command result into some temporary variable: jarPath= find /opt/lotus/notes/ -name $jarFile cho "the jar path $jarPath" where jarPath is temporary variable. Can anybody help on this. Thanks in advance ----Sankar (6 Replies)
Discussion started by: sankar reddy
6 Replies

3. Shell Programming and Scripting

Assigning output to a variable

I am new to unix shell scripting. I was trying to convert each lines in a file to upper case. I know how to convert the whole file. But here i have to do line by line. I am getting it in the below mentioned script #!/bin/bash #converting lower to upper in a file #tr "" "" <file1... (3 Replies)
Discussion started by: jpmena
3 Replies

4. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

5. Shell Programming and Scripting

assigning SED output to a variable = trouble!

i'm on a Mac running BSD unix. i have a script in which i ask the user to input the name of a mounted volume. i then call SED to substitute backslashes and spaces in place of the spaces. that looks like this: echo "Enter the name of the volume" read Volume echo "You've chosen \"$Volume\""... (7 Replies)
Discussion started by: hungryd
7 Replies

6. Shell Programming and Scripting

Problem with assigning output of grep + awk to a variable

Hi All, I am getting the output for the following command when i run it on the unix console. --------------------------- grep `whoami` /etc/passwd | awk '{print ($1);}' | cut -d ":" -f3 ---------------------------- But i made it into a script and tried to print the variable, its... (5 Replies)
Discussion started by: meheretoknow
5 Replies

7. Shell Programming and Scripting

Piping and assigning output to a variable in Perl

Hi All, I am trying to convert the below Csh code into Perl. But i have the following error. Can any expert help ? Error: ls: *tac: No such file or directory Csh set $ST_file = `ls -rt *$testid*st*|tail -1`; Perl my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
Discussion started by: Raynon
10 Replies

8. Shell Programming and Scripting

Assigning Variable to AWK statement

Hi, The following command runs on in the Korn shell prompt. however i want to output the value of this to a variable. Can anyone provide a solution? echo 'ABC,DEF,"G,HI,J",KLM,"MNi,O"'| awk -F "\"" '{for(i=1;i<=NF;i++){if(i%2)gsub("\,","~^~",$i)}}1' (2 Replies)
Discussion started by: ladarlsan
2 Replies

9. Shell Programming and Scripting

Assigning output from awk to variable

I have a script whose contents are as below result= awk 's=100 END {print s }' echo "The result is" $result The desired output is The result is 100 My script is running without exiting and i am also not getting the desired output. Please help (5 Replies)
Discussion started by: bk_12345
5 Replies

10. Shell Programming and Scripting

Assigning bc output to a variable

I'm converting decimal to integer with bc, and I'd like to assign the integer output from bc to a variable 'val'. E.g. In the code below: If b is 5000.000, lines 6 and 8 will output: 5000 (5000.000+0.5)/1 | bc I'd like val to take the value 5000 though, rather than 5000.000 Does someone... (3 Replies)
Discussion started by: pina
3 Replies
getc_putc(8)						      System Manager's Manual						      getc_putc(8)

NAME
getc_putc - program to test hard drive performance. SYNOPSIS
getc_putc [-d dir] [-s size(KiB)] [-m machine-name] [-u uid-to-use:gid-to-use] [-g gid-to-use] DESCRIPTION
This manual page documents briefly the getc_putc, program. This is a simple adjunct to the bonnie++ benchmark. It is used to test various ways of doing IO one byte at a time, usually you don't need to do enough of this for it to be a performance issue for it to matter much which way you do it. But sometimes it's necessary (for example whan parsing IO from a terminal and then launching another process which will take over all IO, such as a simple shell). The real benefits of this are to help settle some arguements about the performance of such things, and to educate novices about how bad per-byte IO really is. OPTIONS
For getc_putc every option is of the form of a hyphen followed by a letter and then the next parameter contains the value. -d the directory to use for the tests. -s the size of the file for byte IO performance measured in kilobytes. NB You can specify the size in mega-bytes if you add 'm' to the end of the number. The default for this test is to test with a 40MiB file. Of the file only 1/32 of it will be used for write() and read() system calls (anything else takes too long), and only 1/4 of it will be used for locked getc() and putc(). -m name of the machine - for display purposes only. -u user-id to use. When running as root specify the UID to use for the tests. It is not recommended to use root, so if you really want to run as root then use -u root. Also if you want to specify the group to run as then use the user:group format. If you spec- ify a user by name but no group then the primary group of that user will be chosen. If you specify a user by number and no group then the group will be nogroup. -g group-id to use. Same as using :group for the -u parameter, just a different way to specify it for compatibility with other pro- grams. -q quiet mode. If specified then some of the extra informational messages will be suppressed. Also the csv data will be the only output on standard out and the plain text data will be on standard error. This means you can run getc_putc -q >> file.csv to record your csv data. OUTPUT
The primary output is plain-text in 80 columns which is designed to fit well when pasted into email and which will work well with Braille displays. The second type of output is CSV (Comma Seperated Values). This can easily be imported into any spread-sheet or database program. For every test the result is a speed in KiB/s. I do not display the CPU time because it presumably is 99% of the power of a single CPU (or something very close to that). AUTHOR
This program, it's manual page, and the Debian package were written by Russell Coker <russell@coker.com.au>. The documentation, the Perl scripts, and all the code for testing the creation of thousands of files was written by Russell Coker, but the entire package is under joint copyright with Tim Bray. SIGNALS
Handles SIGINT and does a cleanup (which may take some time), a second SIGINT or a SIGQUIT will cause it to immidiately die. SIGXCPU and SIGXFSZ act like SIGINT. Ignores SIGHUP. AVAILABILITY
The source is available from http://www.coker.com.au/bonnie++ . See http://etbe.coker.com.au/category/benchmark for further information. SEE ALSO
bonnie++(8), zcav(8) getc_putc(8)
All times are GMT -4. The time now is 03:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy