Sponsored Content
Full Discussion: Cycle for with for-then-else
Top Forums Shell Programming and Scripting Cycle for with for-then-else Post 302844228 by RudiC on Saturday 17th of August 2013 01:02:10 PM
Old 08-17-2013
Quote:
Originally Posted by elilmal
Sorry, but can i insert in to this cycle a command like this?

Code:
#!/bin/bash

SID=xx
symcfg list -sid $SID -pool -gb -det -thin |grep pool |awk '{print $1}' >list_vmax_xx_pools

while read i
do
if [ `symcfg show -sid $SID -pool $i -detail -thin -gb |grep "Max. Subscription Percent"` = 'Enable' ]; then
    echo "ok"
  else
    echo "not ok"
  fi
done < list_vmax_xx_pools

cat list_vmax_xx_pools

pool_1
pool_2
pool_3
You of course can, there's no syntax error, but the way you present it won't yield a reasonable result. symcfg may output whatever it wants, if you grep for "Max Subscription Percent" the output will never be an "Enable" alone.
Why don't you grep for "pool.*Max Subscription Percent" or even "pool.*Max Subscription Percent.*Enable" (as proposed by kshji) in the first place and then work on the results file? Or, maybe, that's already what you desired?
BTW, kshji's last data evaluation could be condensed to
Code:
[ -z "$data" ] && echo "not ok" || echo "OK"

 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell cycle

Hello I got a cycle in the script which open another scripts. if then action fi Scripts action will be running 2 times at the same time. Inside of action() is insert into the table. But what I want is that only first script can do insert into table. So how to do... (2 Replies)
Discussion started by: mape
2 Replies

2. Shell Programming and Scripting

For cycle

Hello, I have files in a dir. I what to create a FOR cycle that will do this FOR <condition> do file=`ls <directory> | tail -1` echo $file mv -f $file <another dir> done What I want to now is what should I put in the <condition>. The condition I want is that the FOR will execute... (3 Replies)
Discussion started by: nagomes
3 Replies

3. Shell Programming and Scripting

wildcard in a if cycle

hello everybody, I need help on putting a wildcard match inside an if condition (I'm using korn shell): if ] then echo ' ' echo ''$MYSEL' is not a correct option' echo ' ' else ..... i tried also #if -ne "``" and a lot of combinations of `"' but I didn't find the... (2 Replies)
Discussion started by: elionba82
2 Replies

4. Shell Programming and Scripting

for cycle

Hello, I have a question: is there a way to have a "for" cycle done a certain number of times. For example in c++ I can do this: for (i=o;i<10;i++) and the cycle will be repeated 10 times. in UNIX for example I do this: for i in `cat /etc/host` do done and the cycle will be repeated... (6 Replies)
Discussion started by: jcpetela
6 Replies

5. Shell Programming and Scripting

for cycle question

i have a question how to modify below script to generate the expect result below : test.sh #!/bin/bash for ((i=0; i < 25; i++)) do echo $1$i done current result: test.sh 20090101 200901010 200901011 200901012 200901013 200901014 200901015 200901016 200901017 200901018 (2 Replies)
Discussion started by: bleach8578
2 Replies

6. Shell Programming and Scripting

sed problem in a for cycle

Hi, i have a problem with a sed command runned in a for cycle... I have a file named fileX which contains (i have crippled the line to minimal for easy): load data dbfoo - TOCHANGE - comment load data dbboo - TOCHANGE - comment load data dbzoo - TOCHANGE - comment ... And a file... (8 Replies)
Discussion started by: maxlamax
8 Replies

7. UNIX for Beginners Questions & Answers

For cycle, process order

Hello, I am running a script under ubuntu 16.04 I have no problem with the script. My question is general algorithm of for file command. I just need to know how for file in *.txt process works. Let's say, I wish to run the script by sorting filename: for file in *.txt do "do something in... (2 Replies)
Discussion started by: baris35
2 Replies
Devel::Cycle(3pm)					User Contributed Perl Documentation					 Devel::Cycle(3pm)

NAME
Devel::Cycle - Find memory cycles in objects SYNOPSIS
#!/usr/bin/perl use Devel::Cycle; my $test = {fred => [qw(a b c d e)], ethel => [qw(1 2 3 4 5)], george => {martha => 23, agnes => 19} }; $test->{george}{phyllis} = $test; $test->{fred}[3] = $test->{george}; $test->{george}{mary} = $test->{fred}; find_cycle($test); exit 0; # output: Cycle(1): $A->{'george'} => \%B $B->{'phyllis'} => \%A Cycle(2): $A->{'george'} => \%B $B->{'mary'} => @A $A->[3] => \%B Cycle(3): $A->{'fred'} => @A $A->[3] => \%B $B->{'phyllis'} => \%A Cycle(4): $A->{'fred'} => @A $A->[3] => \%B $B->{'mary'} => @A # you can also check weakened references weaken($test->{george}->{phyllis}); find_weakened_cycle($test); exit 0; # output: Cycle(1): $A->{'george'} => \%B $B->{'mary'} => @C $C->[3] => \%B Cycle(2): $A->{'george'} => \%B w-> $B->{'phyllis'} => \%A Cycle(3): $A->{'fred'} => @C $C->[3] => \%B $B->{'mary'} => @C Cycle(4): $A->{'fred'} => @C $C->[3] => \%B w-> $B->{'phyllis'} => \%A DESCRIPTION
This is a simple developer's tool for finding circular references in objects and other types of references. Because of Perl's reference- count based memory management, circular references will cause memory leaks. EXPORT The find_cycle() and find_weakened_cycle() subroutine are exported by default. find_cycle($object_reference,[$callback]) The find_cycle() function will traverse the object reference and print a report to STDOUT identifying any memory cycles it finds. If an optional callback code reference is provided, then this callback will be invoked on each cycle that is found. The callback will be passed an array reference pointing to a list of lists with the following format: $arg = [ ['REFTYPE',$index,$reference,$reference_value], ['REFTYPE',$index,$reference,$reference_value], ['REFTYPE',$index,$reference,$reference_value], ... ] Each element in the array reference describes one edge in the memory cycle. 'REFTYPE' describes the type of the reference and is one of 'SCALAR','ARRAY' or 'HASH'. $index is the index affected by the reference, and is undef for a scalar, an integer for an array reference, or a hash key for a hash. $reference is the memory reference, and $reference_value is its dereferenced value. For example, if the edge is an ARRAY, then the following relationship holds: $reference->[$index] eq $reference_value The first element of the array reference is the $object_reference that you passed to find_cycle() and may not be directly involved in the cycle. If a reference is a weak ref produced using Scalar::Util's weaken() function then it won't contribute to cycles. find_weakened_cycle($object_reference,[$callback]) The find_weakened_cycle() function will traverse the object reference and print a report to STDOUT identifying any memory cycles it finds, including any weakened cycles produced using Scalar::Util's weaken(). If an optional callback code reference is provided, then this callback will be invoked on each cycle that is found. The callback will be passed an array reference pointing to a list of lists with the following format: $arg = [ ['REFTYPE',$index,$reference,$reference_value,$is_weakened], ['REFTYPE',$index,$reference,$reference_value,$is_weakened], ['REFTYPE',$index,$reference,$reference_value,$is_weakened], ... ] Each element in the array reference describes one edge in the memory cycle. 'REFTYPE' describes the type of the reference and is one of 'SCALAR','ARRAY' or 'HASH'. $index is the index affected by the reference, and is undef for a scalar, an integer for an array reference, or a hash key for a hash. $reference is the memory reference, and $reference_value is its dereferenced value. $is_weakened is a boolean specifying if the reference is weakened or not. For example, if the edge is an ARRAY, then the following relationship holds: $reference->[$index] eq $reference_value The first element of the array reference is the $object_reference that you passed to find_cycle() and may not be directly involved in the cycle. Cycle Report Formats The default callback prints out a trace of each cycle it finds. You can control the format of the trace by setting the package variable $Devel::Cycle::FORMATTING to one of "raw," "cooked," or "roasted". The "raw" format prints out anonymous memory references using standard Perl memory location nomenclature. For example, a "Foo::Bar" object that points to an ordinary hash will appear in the trace like this: Foo::Bar=HASH(0x8124394)->{'phyllis'} => HASH(0x81b4a90) The "cooked" format (the default), uses short names for anonymous memory locations, beginning with "A" and moving upward with the magic ++ operator. This leads to a much more readable display: $Foo::Bar=B->{'phyllis'} => \%A The "roasted" format is similar to the "cooked" format, except that object references are formatted slightly differently: $Foo::Bar::B->{'phyllis'} => \%A If a reference is a weakened ref, then it will have a 'w->' prepended to it, like this: w-> $Foo::Bar::B->{'phyllis'} => \%A For your convenience, $Devel::Cycle::FORMATTING can be imported: use Devel::Cycle qw(:DEFAULT $FORMATTING); $FORMATTING = 'raw'; Alternatively, you can control the formatting at compile time by passing one of the options -raw, -cooked, or -roasted to "use" as illustrated here: use Devel::Cycle -raw; Code references (closures) If the PadWalker module is installed, Devel::Cycle will also report cycles in code closures. If PadWalker is not installed and Devel::Cycle detects a CODE reference in one of the data structures, it will warn (once per data structure) that it cannot inspect the CODE unless PadWalker is available. You can turn this warning off by passing -quiet to Devel::Cycle at compile time: use Devel::Cycle -quiet; SEE ALSO
Test::Memory::Cycle Devel::Leak Scalar::Util AUTHOR
Lincoln Stein, <lstein@cshl.edu> COPYRIGHT AND LICENSE
Copyright (C) 2003 by Lincoln Stein This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2012-03-21 Devel::Cycle(3pm)
All times are GMT -4. The time now is 03:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy