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 7681137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:16:25+00:00 2026-05-31T18:16:25+00:00

I have a script that runs every minute at XX:00. The script loops over

  • 0

I have a script that runs every minute at XX:00. The script loops over all subfolders in a given directory and performs operations on the files inside;

folder=/path/to/directory #Starting directory
someerror=0 #Did we have an error?

#CD to directory. Does it even exist?
cd $folder
RETVAL=$?
[ $RETVAL -eq 0 ] && echo Success changing directory to $folder && mainfolderexist=1
[ $RETVAL -ne 0 ] && echo Failure changing directory to $folder && mainfolderexist=0

if [ $mainfolderexist -eq 1 ]; then
    shopt -s nullglob
    for dir in $folder/*/
    do
    thedirname=`basename $dir` #Get directory name
    #cd to sub dir. Does it even exist?
    cd $dir
    RETVAL=$?
    [ $RETVAL -eq 0 ] && echo Success changing directory to $dir && subfolderexist=1
    [ $RETVAL -ne 0 ] && echo Failure changing directory to $dir && subfolderexist=0
    if [ $subfolderexist -eq 1 ]; then
        #perform some operation on all files in this directory
        someApp -someArgs --name=$thedirname *
    else #sub folder doesn't exist
        someerror=1
        break
    fi

    #next folder
    done
else #main folder doesn't exist
    someerror=1
fi

#REPEAT (only if no errors occured)
if [ $someerror -eq 0 ]; then
at now + 1 minutes << END
/bin/bash "$0" "$@"
END
fi

The way I use this, is I upload directories to the server using SFTP, to a folder like /home/incoming, and once the directory is fully uploaded I will move it to /path/to/directory. Now this is the part I am worried about.

So far I’ve been making sure to only move directories between XX:XX:02 and XX:XX:50, but is this even neccesary? I would like to automate the upload+move process without taking system time into account so I am wondering;

  1. What if a directory is in the process of getting moved (mv "somedir" "/path/to/directory/somedir") at XX:00 and the script runs, looping over all directories?
  2. What if the system loses power during the mv command? If the directory will end up half moved or something similar, I will have to write a script verifying this before executing the above script.
  • 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-31T18:16:27+00:00Added an answer on May 31, 2026 at 6:16 pm

    If your source and destination paths are on the same filesystem, then mv is an atomic operation. Since it does not actually involve copying or otherwise relocating files, your directories will never end up in a “half-moved” state.

    If, on the other hand, your source and destination paths are on different filesystems, then mv is actually a copy followed by a delete over the entire tree, which can take a substantial amount of time and, if interrupted, will leave things in a half-completed state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that runs every two minutes for a Tweet-getter application. In
I have a php script that runs a mysql query, then loops the result,
I have a php script that is run once a minute. The script runs
I have a script that runs every hour on my php site. In that
I have this bash script on the server that runs every hour, via cron.
I currently have an ASP Classic script that runs every 15 minutes (via scheduled
I have a script that runs every 15 minutes but sometimes if the box
I have a shell script that runs every night to backup my EC2 sites
I have a email script that runs every 15 minutes and is supposed to
I have a jQuery script that runs a function every second with setinterval. But

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.