Question on Initializing the Variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question on Initializing the Variable
# 1  
Old 04-14-2008
Question on Initializing the Variable

What i am trying to do is cd to my directory first. If any of that folder contains "volcano" folder then create the same directory structure in the remote machine "lexus". This is what i am doing.

Code:
LOCAL_LOG_FILE="logging.log"
DEST_DIR="/test/ferrari/testing"
cd /home/mike/
for dir in $DATA_DIR; do
   if [ -d ${dir}/"volcano" ]; then

   /usr/local/bin/ssh -l abc lexus "mkdir -p 777  $DEST_DIR/$dir" >>$LOCAL_LOG_FILE 2>&1
    scp -r ${dir}/"volcano" lexus:$DEST_DIR/${dir}/
    fi
    done

    exit 0

The code i posted works fine. It creates the appropriate directories as needed in the remote machine.

/test/ferrari/testing/joe/volcano/abc.txt
/test/ferrari/testing/mike/volcano/xyz.txt

But if i just put that "cd /home/mike" in a variable it creates the home directories also :-

Code:
   DATA_DIR="/home/mike/*"
   DEST_DIR="/test/ferrari/testing"

   for dir in $DATA_DIR; do
   if [ -d ${dir}/"volcano" ]; then

   /usr/local/bin/ssh -l abc lexus "mkdir -p 777  $DEST_DIR/$dir" >>$LOCAL_LOG_FILE 2>&1
    scp -r ${dir}/"volcano" lexus:$DEST_DIR/${dir}/
    fi
    done

    exit 0

The directory structure lookslike this on my remote machine:-

/test/ferrari/testing/home/mike/joe/volcano/abc.txt
/test/ferrari/testing/home/mike/joe/volcano/xyz.txt

Instead it should create :-

/test/ferrari/testing/joe/volcano/abc.txt
/test/ferrari/testing/mike/volcano/xyz.txt

Can someone tell me why this is happening?
# 2  
Old 04-14-2008
Quote:
Originally Posted by chris1234
Code:
   DATA_DIR="/home/mike/*"
   DEST_DIR="/test/ferrari/testing"

   for dir in $DATA_DIR; do

if you look at how the for line will be expanded using the variable then you will understand.
Code:
for dir in /home/mike; do

I think it should be:
Code:
for dir in `ls $DATA_DIR`; do

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

AIX 7.2 - Error initializing a device into the kernel.

On a fresh bare metal (no LPARs) install of AIX 7.2 running cfgmgr is returning.. # cfgmgr Method error (/usr/lib/methods/cfgstorfworkcom -l sfwcomm2 ): 0514-040 Error initializing a device into the kernel. Method error (/usr/lib/methods/cfgstorfworkcom -l sfwcomm3 ): ... (1 Reply)
Discussion started by: c3rb3rus
1 Replies

2. Shell Programming and Scripting

Variable to command to Variable Question KSH

Hello, First post for Newbie as I am stumped. I need to get certain elements for a specific PID from the ps command. I am attempting to pass the value for the PID I want to retrieve the information for as a variable. When the following is run without using a variable, setting a specific PID,... (3 Replies)
Discussion started by: Coyote270WSM
3 Replies

3. Shell Programming and Scripting

initializing a blank hard disk

I have a blank hard disk - no partitions, no file system, no label, no nothing - that I need to reuse. In a shell script, how do I get it to where I can write data to it again? I've looked at the man parted page, but I can't tell which command to run, or which sequence of commands. Thanks. (2 Replies)
Discussion started by: daflore
2 Replies

4. UNIX for Dummies Questions & Answers

Initializing multiple variables in one statement

HI, I have 5 variables var1, var2, var3, var4 and var5 I need to initialize all of them to zero. Is there a way to do it in a single line something like this var1=var2=var3=var4=var5=0. I am unable to achieve this. What is going wrong? (2 Replies)
Discussion started by: paku
2 Replies

5. Shell Programming and Scripting

Initializing empty string with spaces

Hi, I want to Initialize a String with 50 spaces. I can do that by ex: Var1=" " But i dont want to do in this way? Is there any unix command where i can specify no of spaces to a varaible? like space(50) (1 Reply)
Discussion started by: Shiv_18
1 Replies

6. Shell Programming and Scripting

Array not initializing

Hi, I have to use array in shell script to perform a logic. When I use below statements inside a script and execute, it gives me an error: $ cat test.sh set -A arr 10 20 30 echo ${arr} $ sh test.sh a: -A: bad option(s) But at the same time I can run above two statements without error... (3 Replies)
Discussion started by: nandanjain
3 Replies

7. UNIX for Dummies Questions & Answers

Initializing files to empty in korn shell

hello, i want to know how to initialize a file to an empty one in korn shell scripting? i'm using a file name and building it during a while loop using >>. The problem occurs when the file is not empty before reaching the while loop. therefore, i want to initialize it before the loop to get... (6 Replies)
Discussion started by: alrinno
6 Replies

8. Linux

Problem with initializing DirectFB by Links

DirectFB-0.9.20 is compiled --with-gfxdrivers=all links-2.1pre15 is compiled with --enable-graphics there is a problem when I am trying to run Links using DirectFB video driver may be my DirectFBs config is not right? video by framebuffer or X works successfully (0 Replies)
Discussion started by: eugrus
0 Replies

9. UNIX for Dummies Questions & Answers

Re-initializing startup files without rebooting

Sorry for the newbie question. I'm using OSX BSD by remotely logging in and need to re-initialize the startup sequence but don't want to reboot the machine. How can I do it? Thanks for any help. (3 Replies)
Discussion started by: DrScar
3 Replies
Login or Register to Ask a Question