Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 772195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:46:19+00:00 2026-05-14T18:46:19+00:00

At work, we have 7 or 8 hardrives we dispatch over the country, each

  • 0

At work, we have 7 or 8 hardrives we dispatch over the country, each have unique labels which are not sequential.

Ideally drives are plugged in our desktop, then gets folders from the server that correspond to the drive name.

Sometimes, only one hard drive gets plugged in sometimes multiples, possibly in the future more will be added.


Each is mounted to /Volumes/ and its identifier; so for example /Volumes/f00, where f00 is the identifier.

What I want to happen, scan volumes see if any any of the drives are plugged in, then check the server to see if the folder exists, if it does copy folder and recursive folders.


Here is what I have so far, it checks if the drive exists in Volumes:

#!/bin/sh

#Declare drives in the array

ARRAY=( foo bar long )


#Get the drives from the array
DRIVES=${#ARRAY[@]}

#Define base dir to check
BaseDir="/Volumes"


#Define shared server fold on local mount points
#I plan to use AFP eventually, but for the sake of ease
#using a local mount.
ServerMount="BigBlue"

#Define folder name for where files are to come from
Dispatch="File-Dispatch"

dir="$BaseDir/${ARRAY[${i}]}"


#Loop through each item in the array and check if exists on /Volumes
for (( i=0;i<$DRIVES;i++));
do
  dir="$BaseDir/${ARRAY[${i}]}"
    if [ -d "$dir"  ]; then
    echo "$dir exists, you win."
  else
    echo "$dir is not attached."
    fi
done

What I can’t figure out how to do, is how to check the volumes for the server while looping through the harddrive mount points.

So I could do something like:

#!/bin/sh

#Declare drives, and folder location in arrays

ARRAY=( foo bar long )



#Get the drives from the array

DRIVES=${#ARRAY[@]}


#Define base dir to check
BaseDir="/Volumes"

#Define shared server fold on local mount points

ServerMount="BigBlue

#Define folder name for where files are to come from
Dispatch="File-Dispatch"

dir="$BaseDir/${ARRAY[${i}]}"

#List the contents from server directory into array


ARRAY1=($(ls ""$BaseDir"/"$ServerMount"/"$Dispatch""))
SERVERFOLDER=${#ARRAY1[@]}

echo ${list[@]}

for (( i=0;i<$DRIVES;i++)); (( i=0;i<$SERVERFOLDER;i++)); 
do
  dir="$BaseDir/${ARRAY[${i}]}"
  ser="${ARRAY1[${i}]}"
    if [ "$dir" =~ "$sir" ]; then
    cp "$sir" "$dir"
  else
    echo "$dir is not attached."
    fi
done

I know, that is pretty wrong… well very, but I hope it gives you the idea of what I am trying to achieve.

Any ideas or suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:46:20+00:00Added an answer on May 14, 2026 at 6:46 pm

    Some notes:

    • You’re using variables before you define them (I see that you set this variable a second time in a more appropriate place) and those quotes are unnecessary:
      ARRAY1=($(ls "$BaseDir/$ServerMount/$Dispatch"))
    • Missing closing quote:
      ServerMount="BigBlue"
    • Using curly braces when they’re not necessary hinders readability (you could also omit the dollar sign for array subscripts):
      dir="$BaseDir/${ARRAY[i]}"
    • This array isn’t defined:
      echo ${list[@]}
    • Huh? I think you may want nested for loops and you have to use different variables. Instead of:
      for (( i=0;i<$DRIVES;i++)); (( i=0;i<$SERVERFOLDER;i++));
      try:
       for (( i= ...
       do  
           for (( j= ...  
           do
               dir="$BaseDir/${ARRAY[i]}"
               ser="${ARRAY1[j]}"
    • You should be aware that if the filenames or directory names have spaces in them, iterating over an array will fail. The alternative is to pipe find into a while...read loop.
    • Here you call it “ser” and then you call it “sir”:
      ser="${ARRAY1[i]}"
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.