Sponsored Content
Full Discussion: Variable lost outside a loop
Top Forums Shell Programming and Scripting Variable lost outside a loop Post 302968314 by balajesuri on Tuesday 8th of March 2016 12:05:44 AM
Old 03-08-2016
bash code:
  1. # create array. take care of the syntax .. spaces and parenthesis
  2. ignoreTables=( visitors_15012016 visitors_Original )
  3.  
  4. # take an initial dummy empty variable for building the required string
  5. # we need --ignore-table=tbl1 --ignore-table=tbl2 and so on...
  6. ignoreString=''
  7. # loop over the array. ${arr_var[@]} simply gives back all the elements of the array
  8. for tbl in ${ignoreTables[@]}
  9. do
  10.     # build the string variable. with each pass of the loop, the new table name is appended to the old one along with the mysqldump switch "--ignore-table"
  11.     ignoreString=${ignoreString}"--ignore-table="${tbl}" "
  12. done
  13. # now at the end of loop, ignoreString contains
  14. # "--ignore-table=tbl1 --ignore-table=tbl2"
  15. # use it in the below command
  16.  
  17. mysqldump --log-error=/var/log/mysql-dump/dump.log -u USER -pPASSWD DBName $ignoreString | bzip2 > /path2file/file.sql.bz2

Last edited by balajesuri; 03-08-2016 at 01:12 AM..
 

9 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Lost Data Lost Admin

First time so excuse my ignorance please. I may not be accurately describing the issue. I have inherited a small lab mostly SUN V120s. We lost power and are trying to recover. Nope no backups... The primary issue I have is 1 box is an Oracle Server. It has 2 36Gb harddrives. I am able to... (3 Replies)
Discussion started by: murphsr
3 Replies

2. UNIX for Dummies Questions & Answers

Variable gets lost

Hi Please help! Am using unix AIX... The variable i use in the beggining of the shell script gets lost after i call the sqlldr and sql plus...no changes being done anywhere else... Thanks... (1 Reply)
Discussion started by: esh.mohan
1 Replies

3. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

4. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

5. Shell Programming and Scripting

printing variable with variable suffix through loop

I have a group of variables myLINEcnt1 - myLINEcnt10. I'm trying to printout the values using a for loop. I am at the head banging stage since i'm sure it has to be a basic syntax issue that i can't figure out. For myIPgrp in 1 2 3 4 5 6 7 8 9 10; do here i want to output the value of... (4 Replies)
Discussion started by: oly_r
4 Replies

6. UNIX for Dummies Questions & Answers

Loop and variable not exactly variable: what's wrong

Hello guys, This truly is a newbie question. I'm trying to make a loop to execute simultaneous commands indefinitely while using variable. Here is how my mess looks like (this is just an example): #!/bin/bash IP=`shuf -n 1 IP.txt` # I figured this would be easier to select random lines... (4 Replies)
Discussion started by: bobylapointe
4 Replies

7. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

8. Shell Programming and Scripting

Attempting to pass my array as a nested parameter to loop. A little lost.

I want to pass this array as a parameter. IFS=$'\n' fortune_lines=($(fortune | fold -w 30 )) Inside of this line screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say ${fortune_lines}\r"`" And I am lost at this point. I am thinking something like this? Then make it loop.. ... (7 Replies)
Discussion started by: briandanielz
7 Replies

9. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies
All times are GMT -4. The time now is 03:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy