Timing an operation

2007-05-24 Thread Matthew_S

Hi all,

I'm fairly new to Bash so if I appear slow that's the reason ;)

I'm trying to write a function that will give me the time it takes to do an
operation and then report to a logfile if it passes or fails.  What I have
so far is;

functionName()
{
echo Timing the function. >> $LOG
date
$FUNCTION
date
}

but this means I will manually have to calculate the difference between the
two dates.  Can i have something like;

if 
difference between dates <5seconds 
echo fail
fi

??

Thanks in advance,

Matthew.
-- 
View this message in context: 
http://www.nabble.com/Timing-an-operation-tf3809131.html#a10780790
Sent from the Gnu - Bash mailing list archive at Nabble.com.



___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Timing an operation

2007-05-25 Thread Matthew_S

Thanks Paul and Chet;

They both do the same thing and that's exactly what I was looking for.

Thanks again,

Matthew.


Chet Ramey wrote:
> 
> Paul Jarc wrote:
> 
>> date1=`perl -e 'print time()'`
>> ...
>> date2=`perl -e 'print time()'`
>> interval=`expr "$date2" - "$date1"`
> 
> This general approach can be used without invoking any external programs:
> 
> date1=$SECONDS
> ...
> date2=$SECONDS
> interval=$(( $date2 - $date1 ))
> 
> Chet
> -- 
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  Live Strong.  No day but today.
> Chet Ramey, ITS, CWRU[EMAIL PROTECTED]   
> http://cnswww.cns.cwru.edu/~chet/
> 
> 
> ___
> Bug-bash mailing list
> Bug-bash@gnu.org
> http://lists.gnu.org/mailman/listinfo/bug-bash
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Timing-an-operation-tf3809131.html#a10799786
Sent from the Gnu - Bash mailing list archive at Nabble.com.



___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Timing an operation

2007-05-25 Thread Matthew_S

Sorry guys, I need to take it a step further and am hitting a wall at the
moment;

I need to take two results (from you examples), compare them and get a final
result.  What I have thus far is;

operation()
{
echo >> $LOG
echo Running operation>> $LOG
for i in a b 
do
mkdir $DIR/dir$i
cd $DIR/dir$i
date1=$SECONDS
operation
date2=$SECONDS
interval$i=$(($date2 - $date1)) #1st & 2nd errors
echo Operation took $interval second. >> $LOG
rm -rf *
cd /
umount $DIR
done
echo The 2nd time difference should be quicker than the 1st >> $LOG
interval=$(($interval8 - $interval2048)) >> $LOG #3rd error
if test 5 -gt "$interval"; then
echo fail
else
echo pass
fi
}

I'm getting the errors;
./file.sh: line x: intervala=1: command not found
./file.sh: line x: intervalb=1: command not found
./file.sh: line x: - : syntax error: operand expected (error token is " ")

It seems so simple in my head, but I don't know how to execute it...

Any help would be greatly appreciated.

Thanks

Matthew.



Matthew_S wrote:
> 
> Thanks Paul and Chet;
> 
> They both do the same thing and that's exactly what I was looking for.
> 
> Thanks again,
> 
> Matthew.
> 
> 
> Chet Ramey wrote:
>> 
>> Paul Jarc wrote:
>> 
>>> date1=`perl -e 'print time()'`
>>> ...
>>> date2=`perl -e 'print time()'`
>>> interval=`expr "$date2" - "$date1"`
>> 
>> This general approach can be used without invoking any external programs:
>> 
>> date1=$SECONDS
>> ...
>> date2=$SECONDS
>> interval=$(( $date2 - $date1 ))
>> 
>> Chet
>> -- 
>> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>> Live Strong.  No day but today.
>> Chet Ramey, ITS, CWRU[EMAIL PROTECTED]   
>> http://cnswww.cns.cwru.edu/~chet/
>> 
>> 
>> ___
>> Bug-bash mailing list
>> Bug-bash@gnu.org
>> http://lists.gnu.org/mailman/listinfo/bug-bash
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Timing-an-operation-tf3809131.html#a10800402
Sent from the Gnu - Bash mailing list archive at Nabble.com.



___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Taking input line by line from a config file in Bash

2008-01-02 Thread Matthew_S

Hi all and firstly… Happy New Year!

It wouldn’t be a New Year without a New Problem though ;-)

I’m trying to create a script that will take the input of a config file line
by line.  Unfortunately, what seems to be happening is that it is taking it
though word by word instead?

For arguments sake I’ve put ‘I want this whole line on one line’ into the
config file and the script looks like this;

for i in `cat config.txt`
do echo $i
echo >> $RESULTS
echo $i >> $RESULTS
$i
[ $? == 0 ] && echo "PASSED" >> $RESULTS || echo "FAILED" >>
$RESULTS
Done

And here are the results;

I
./filesystem_test.sh: line 12: I: command not found
want
./filesystem_test.sh: line 12: want: command not found
this
./filesystem_test.sh: line 12: this: command not found
whole
./filesystem_test.sh: line 12: whole: command not found
line
./filesystem_test.sh: line 12: line: command not found
on
./filesystem_test.sh: line 12: on: command not found
one
./filesystem_test.sh: line 12: one: command not found
line
./filesystem_test.sh: line 12: line: command not found

It’s been suggested that I try read and so I have this;

File=./config.txt

{
read line
echo $i
echo >> $RESULTS
echo $i >> $RESULTS
$i
[ $? == 0 ] && echo "PASSED" >> $RESULTS || echo "FAILED" >>
$RESULTS
} < $File

But need to get the numbered input from by using cat -n on the config file,
but the space delimiter in cut doesn’t seem to allow me to select only the
numbers?  Which means I can’t run something like;

for i in `cat -n config.txt | cut -d' ' -f1
do read line $i
etc…

Any help or guidance would be greatly appreciated.

Many thanks.

Matthew.
-- 
View this message in context: 
http://www.nabble.com/Taking-input-line-by-line-from-a-config-file-in-Bash-tp14575394p14575394.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: Taking input line by line from a config file in Bash

2008-01-02 Thread Matthew_S

Hi Bob,

Thanks for the quick reply.

With the 'while read line', it appears that I don't need to keep track of
the line numbers.  In fact this below does exactly what I need it to do;

cat $File |   # Supply input from a file
while read line   # As you suggested...

do echo $line
echo >> $RESULTS
echo $line >> $RESULTS
$line
[ $? == 0 ] && echo "PASSED" >> $RESULTS || echo "FAILED" >>
$RESULTS
done

exit

Thanks again.

Matthew.
-- 
View this message in context: 
http://www.nabble.com/Taking-input-line-by-line-from-a-config-file-in-Bash-tp14575394p14575880.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: Taking input line by line from a config file in Bash

2008-01-03 Thread Matthew_S

I see what you're saying.  That's interesting about cat, thanks for the heads
up.

while read line
do
{
echo
$line > /dev/null && echo $line "PASSED" || echo $line
"FAILED"
} >> $RESULTS
done < $FILE
exit 0

This does the same thing, but seems to be more streamline... cleaner.  Those
are some useful points for future reference.  Thanks again.

Matthew
-- 
View this message in context: 
http://www.nabble.com/Taking-input-line-by-line-from-a-config-file-in-Bash-tp14575394p14593790.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Finding out current inode size

2008-01-03 Thread Matthew_S

I've been trawilng the web trying to find out how to get the current inode
size for a file.  I now know how to change the max inode size for the
system;

mkfs -i size=xxx

which also begs the question how to find out the current limit of the
system.  I'm guessing it'll be the default 256 bytes, but I'd like to be
sure.

The reason I'd like to know the current inode size of a file is because I'd
like to create a large enough number of extended attributes in order to test
the inodes boundaries and the subsequent handling.
-- 
View this message in context: 
http://www.nabble.com/Finding-out-current-inode-size-tp14599119p14599119.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: Taking input line by line from a config file in Bash

2008-01-08 Thread Matthew_S

I'm having a bit of trouble with one of the lines in my config file.  'ls -l
| cut -d ' ' -f1' doesn't want to pass through the script.  Here's the
output;

ls -l | cut -d ' ' -f1
ls: |: No such file or directory
ls: cut: No such file or directory
ls: ': No such file or directory
ls: ': No such file or directory

It seems to think I want to do an ls on the | etc. and isn't treating the
line as a command as a whole like all the other commands are treated.

I've tried placing it in '' "" & `` but none of those work.  I'm not sure
how to get this line through?
-- 
View this message in context: 
http://www.nabble.com/Taking-input-line-by-line-from-a-config-file-in-Bash-tp14575394p14690151.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.