Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Nested If statement within Do / Done Post 302382123 by dalgibbard on Tuesday 22nd of December 2009 07:51:46 AM
Old 12-22-2009
Lightbulb Nested If statement within Do / Done

Hi all!
I'm really hoping you can help me out here; now i have searched and searched and have at least worked out that you can't have a nested if statement with a 'done' in it (as i have) as you're killing the parent before the child.

So here's what i have, and here's hoping someone can help me think of a work around! FYI, i'm using bash on a custom linux build, fairly standard based around red hat i believe(?)

The script is to find all attached USB devices, and copy a folders contents to it. The issue is within the variable check at the start, and the two unmounting after replication parts.

Theres a few other parts later on which i haven't posted which have a similar issue- so any ideas would be great! Smilie

Code:
# Assigning Drive variables and locating available disks.
alldrives=$(df -h | grep sda | awk '{print$1}' | cut -c1-8)
d1=$(echo $alldrives | awk '{print$1}')
d2=$(echo $alldrives | awk '{print$2}')
d3=$(echo $alldrives | awk '{print$3}')
d4=$(echo $alldrives | awk '{print$4}')
d5=$(echo $alldrives | awk '{print$5}')
d6=$(echo $alldrives | awk '{print$6}')
d7=$(echo $alldrives | awk '{print$7}')
d8=$(echo $alldrives | awk '{print$8}')
d9=$(echo $alldrives | awk '{print$9}')
d10=$(echo $alldrives | awk '{print$10}')
 
for i in $d1 $d2 $d3 $d4 $d5 $d6 $d7 $d8 $d9 $d10
do
 
if [[ -z $i ]]
then
echo "Variable blank, moving to next"
done
fi
 
#CHECK FOR MOUNTABLE DRIVE, MAKE DIR FOR IT
mkdir /mnt/clone/
if mount "$i""1" /mnt/clone/"$i""1"
then
 
 
# START REPLICATION
echo "BEGINNING RSYNC REPLICATION"
rsync -rtv --progress --modify-window=1 --exclude=LOCAL.CFG /usr/local/FOLDER1 /mnt/clone/"$i""1"/usr/local/FOLDER1
echo
 
 
# UNMOUNT AFTER REPLICATION
if umount /mnt/clone/"$i""1"
then
echo "Unmounted Successfully. Copying Complete."
 
done
else
 
 
# FORCE IF UNABLE TO UNMOUNT
echo "Forcing unmount..."
sync
sleep 15
cd /
umount -f /mnt/clone/"$i""1"
done
fi
 
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nested Arrays

Hi, I'm trying to implement nested arrays in ksh. i've the follwing arrays SRV=\ "SRV1 "\ "SRV2 " SRV1=\ "MD11 "\ "MD12 " SRV2=\ "MD21 "\ "MD22 " MD11=\ "ABC " (5 Replies)
Discussion started by: guysporty
5 Replies

2. Shell Programming and Scripting

while read loop w/ a nested if statement - doesn't treat each entry individually

Hi - Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert. The list file (ldaplist) would look like - *********** o=company a o=company b *********** **... (7 Replies)
Discussion started by: littlefrog
7 Replies

3. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

4. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

5. Shell Programming and Scripting

If-statement nested in case

I'm trying to write case statements with 'if statements' embedded inside of them. I'm using the korn shell but it's not functioning. If I want to see if a string exists in a file and then perform an action, what would be the best way to do this? For file "asg51fin" to delete a line if a... (1 Reply)
Discussion started by: dazeman27
1 Replies

6. Shell Programming and Scripting

Perl nested if statement

I'm just having a bit of trouble running this code. It tells me that there's a syntax error on line 29. Any help appreciated. #!/usr/bin/perl # # Phone Book Application # %phonebook = ( "Wayne", '34687368', "Home", '378643287', "Work", '017374637', "School",... (2 Replies)
Discussion started by: cabaiste
2 Replies

7. UNIX for Dummies Questions & Answers

Nested If in Unix

Hi!! LookVar=`find . -name "${input}" | wc -w` if then cd $input rm -f * ftp -n -i $HostName << EOF quote USER $User quote PASS $Password cd $Path SoLookVar=`find . -name "${input}" | wc -w` echo $SoLookVar if then cd $input mget ./* bye EOF chmod 775 ./* (12 Replies)
Discussion started by: Afsana
12 Replies

8. Shell Programming and Scripting

Nested if else

Hi, i m trying to create script which logic is like below. if ; then x=`cat /tmp/testoutput.log | grep STOP | wc -l` y=`cat /tmp/testoutput.log | grep RUN | wc -l` if ; then echo "process stop" if ; then echo "process running " else echo "file not found" fi ----------------... (2 Replies)
Discussion started by: tapia
2 Replies

9. UNIX for Dummies Questions & Answers

[Solved] Nested If

I am having a problem with a nested if. I am sure I am overlooking something. I check for the existence of $Pidfl3 and it exists, o this condition I then want to check for the existence of a next file and remove it. The first if is executed, but on the second if I get test: argument expected. My... (4 Replies)
Discussion started by: Charles Swart
4 Replies

10. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies
Test::Aggregate::Nested(3pm)				User Contributed Perl Documentation			      Test::Aggregate::Nested(3pm)

NAME
Test::Aggregate::Nested - Aggregate "*.t" tests to make them run faster. VERSION
Version 0.364 SYNOPSIS
use Test::Aggregate::Nested; my $tests = Test::Aggregate::Nested->new( { dirs => $aggregate_test_dir, verbose => 1, } ); $tests->run; DESCRIPTION
ALPHA WARNING: this is alpha code. Conceptually it is superior to "Test::Aggregate", but in reality, it might not be. We'll see. This module is almost identical to "Test::Aggregate" and will in the future be the preferred way of aggregating tests (until someone comes up with something better :) "Test::Aggregate::Nested" requires a 0.8901 or better of "Test::More". This is because we use its "subtest" function. Currently we "croak" if this function is not available. Because the TAP output is nested, you'll find it much easier to see which tests result in which output. For example, consider the following snippet of TAP. 1..2 1..5 ok 1 - aggtests/check_plan.t ***** 1 ok 2 - aggtests/check_plan.t ***** 2 ok 3 # skip checking plan (aggtests/check_plan.t ***** 3) ok 4 - env variables should not hang around ok 5 - aggtests/check_plan.t ***** 4 ok 1 - Tests for aggtests/check_plan.t 1..1 ok 1 - subs work! ok 2 - Tests for aggtests/subs.t At the end of each nested test is a summary test line explaining which program we ran tests for. "Test::Aggregate::Nested" asserts a plan equal to the number of test files aggregated, something which "Test::Aggregate" could not do. Because of this, we no longer export "Test::More" functions. If you need additional tests before or after aggregation, you'll need to run the aggregated tests in a subtest: use Test::More tests => 2; use Test::Aggregate::Nested; subtest 'Nested tests' => sub { Test::Aggregate::Nested->new({ dirs => 'aggtests/' })->run; }; ok $some_other_test; CAVEATS
"Test::Aggregate::Nested" is much cleaner than "Test::Aggregate", so I don't support the "dump" argument. If this is needed, let me know and I'll see about fixing this. The "variable will not stay shared" warnings from "Test::Aggregate" (see its CAVEATS section) are no longer applicable. AUTHOR
Curtis Poe, "<ovid at cpan.org>" BUGS
Please report any bugs or feature requests to "bug-test-aggregate at rt.cpan.org", or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Aggregate <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Aggregate>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT
You can find documentation for this module with the perldoc command. perldoc Test::Aggregate You can also look for information at: o AnnoCPAN: Annotated CPAN documentation http://annocpan.org/dist/Test-Aggregate <http://annocpan.org/dist/Test-Aggregate> o CPAN Ratings http://cpanratings.perl.org/d/Test-Aggregate <http://cpanratings.perl.org/d/Test-Aggregate> o RT: CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Aggregate <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Aggregate> o Search CPAN http://search.cpan.org/dist/Test-Aggregate <http://search.cpan.org/dist/Test-Aggregate> ACKNOWLEDGEMENTS
Many thanks to mauzo (<http://use.perl.org/~mauzo/> for helping me find the 'skip_all' bug. Thanks to Johan LindstrA~Xm for pointing me to Apache::Registry. COPYRIGHT &; LICENSE Copyright 2007 Curtis "Ovid" Poe, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-08-27 Test::Aggregate::Nested(3pm)
All times are GMT -4. The time now is 04:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy