The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Another variable question, I think NycUnxer UNIX for Dummies Questions & Answers 2 02-28-2008 08:30 PM
VAriable Question rjsha1 Shell Programming and Scripting 4 02-07-2006 05:03 AM
Question about breaking up a variable krism Shell Programming and Scripting 2 09-19-2005 01:08 PM
Problem with initializing DirectFB by Links eugrus Linux 0 01-15-2005 10:13 AM
Re-initializing startup files without rebooting DrScar UNIX for Dummies Questions & Answers 3 08-20-2001 07:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-14-2008
Registered User
 

Join Date: Apr 2006
Posts: 74
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?
Reply With Quote
Forum Sponsor
  #2  
Old 04-14-2008
wempy's Avatar
Registered User
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 177
Quote:
Originally Posted by chris1234 View Post
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0