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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:28:58+00:00 2026-05-20T15:28:58+00:00

Looking for some help with my bash script. I am trying to write this

  • 0

Looking for some help with my bash script. I am trying to write this shell script to do the following:

  1. find files in a dir named:
    server1-date.done
    server2-date.done
    server3-date.done
    ...
    server10-date.done

  2. print to a listA

  3. find files in a dir (*.gz) and print to a listB
  4. if listA has a count of 10 (basically found 10 .done files), then
    proceed with the moving the files in listB to its new directory
  5. after moving the files from listB, then remove the old directory which is similarly named (server1-date, server2-date, …) and the .done files.

So far, I have this in the works. I can’t get the condition for the if section working. I don’t think I coded that correctly. Any code suggestions, improvements, etc would be appreciated. Thanks.

#Directories
GZDIR=/mydumps/mytest
FINALDIR=/mydumps/mytest/final
FLGDIR=/backup/mytest/flags
export GZDIR FINALDIR FLGDIR

#lists
FLGLIST="/mydumps/mytest/lists/userflgs.lst"
GZLIST="/mydumps/mytest/lists/gzfiles.lst"
export FLGLIST GZLIST

#Find files
find $FLGDIR -name \*.done -print > $FLGLIST
find $GZDIR -name \*.gz -print > $GZLIST

#Get need all (10) flags found before we do the move
FLG_VAL =`cat $FLGLIST | wc -l`
export $FLG_VAL

if [ "$FLG_VAL" = "10" ]; then
   for FILE in $GZLIST
       do
       echo "mv $GZLIST $FINALDIR" 2>&1
          for FLAG in $FLGLIST
             do
             echo "rmdir -f $FLAG" 2>&1
             done
       done
       else
           echo "Cannot move file" 2>&1
      exit 0
fi
  • 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-20T15:28:58+00:00Added an answer on May 20, 2026 at 3:28 pm

    I do not know if this will work, but it will fix all the obvious problems:

    #!/bin/sh
    #Directories
    GZDIR=/mydumps/mytest
    FINALDIR=/mydumps/mytest/final
    FLGDIR=/backup/mytest/flags
    export GZDIR FINALDIR FLGDIR
    
    #lists
    FLGLIST="/mydumps/mytest/lists/userflgs.lst"
    GZLIST="/mydumps/mytest/lists/gzfiles.lst"
    
    #Find files
    find "$FLGDIR" -name '*.done' -print > "$FLGLIST"
    find "$GZDIR" -name '*.gz' -print > "$GZLIST"
    
    #Get need all (10) flags found before we do the move
    FLG_VAL=$(wc -l <"$FLGLIST")  # Always prefer $( ... ) to backticks.
    
    if [ "$FLG_VAL" -ge 10 ]; then
        for FILE in $(cat "$GZLIST")
            do
            echo "mv $FILE $FINALDIR" 2>&1
        done
        for FLAG in $(cat "$FLGLIST")
            do
            echo "rmdir -f $FLAG" 2>&1
        done
    else
        echo "Cannot move file" 2>&1
        exit 0
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for some help. I have found this script that sort of
I'm looking for some help with the following. This will be a very general
I'm looking for some help to implent a timer for this script I'm linking
Im looking for some help on information on files using Power shell, we have
Looking for some help with my SQL query. I am trying to find a
Looking for some help on my AJAX/jQuery implementation. I am trying to load some
I´m looking for some help about my shopping cart. I use a simple script.
I am looking for some help in a jquery script I am in the
I'm trying to write a bash script that takes a file name, and return
I'm looking for some help to get rid of this error. As i'm running

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.