0

I'm sorry if something similar was already answered in the past, but I wasn't able to find it. I'm writing a script to perform some housekeeping tasks, and I get stuck in the step below. To put you in the record, it's a script which reads a config file in order to be able to use it as standard protocol in different environments.

The problem is with this code:

# Check if destination folder exist, if not create it.
    if [ ! -d ${V_DestFolder} ]; then # Create folder
        F_Log "${IF_ROOT} mkdir -p ${V_DestFolder}"
        ${IF_ROOT} mkdir -p ${V_DestFolder}
        continue
    fi        

    # If movement, check write permissions of destination folder.
    V_CheckIfMovement=`echo $1|grep @`
    if [ $? -eq 0 ]; then # File will be moved.
      V_DestFolder=`echo $1|awk -F"@" {'print $2'}`
      if [ ! -w ${V_DestFolder} ]; then # Destination folder IS NOT writable.
        F_Log "Destination folder ${V_DestFolder} does not have WRITE permissions. Skipping."
        continue
      fi
    fi

Basically I need to move (in this step) some files from one route to another.
It checks if the folder (name read from config file) exists, if not it will be created, after that check if the folder have write rights and move the files.

Here you can see the part of config file which is read in this step:

app/tom*/instances/*/logs|+9|/.*\.gz)$/|move@/app/archive/tom*/logs

I need to say the files are properly moved when I change the tom* of the destination for anything, as "test" or any word without * (as it should).

What I need to know is how I can use a variable in "tom*" in destination. Variable should contain the same name of tom* in the source, which I use as the name of the cell.

This is because I use different tomcat cells with the reference tom7 or tom8 plus 3 letters to describe each one. as example tom7dog or tom7cat.

JamCon
  • 2,313
  • 2
  • 25
  • 34
jota
  • 1
  • Can you give more information about the meaning of the entry in the config file? I assume the part left of |move@ is the source and right of it the target? There is also only a closing ). Is there an opening ( also ? – monok Mar 04 '19 at 09:22

1 Answers1

0

You should give the shell a chance to evaluate.

V_DestFolder=`echo $1|awk -F"@" {'print $2'}`
for p in ${V_DestFolder}; do
      if [ ! -w ${p} ]; then 
Walter A
  • 19,067
  • 2
  • 23
  • 43