Bash - Check directory for files against list of partial file names

Arronical

I have a server which receives a file per client each day into a directory. The filenames are constructed as follows:

uuid_datestring_other-data

For example:

d6f60016-0011-49c4-8fca-e2b3496ad5a7_20160204_023-ERROR
  • uuid is a standard format uuid.
  • datestring is the output from date +%Y%m%d.
  • other-data is variable in length but will never contain an underscore.

I have a file of the format:

#
d6f60016-0011-49c4-8fca-e2b3496ad5a7    client1
d5873483-5b98-4895-ab09-9891d80a13da    client2
be0ed6a6-e73a-4f33-b755-47226ff22401    another_client
...

I need to check that every uuid listed in the file has a corresponding file in the directory, using bash.

I've got this far, but feel like I'm coming from the wrong direction by using an if statement, and that I need to loop through the files in the source directory.

The source_directory and uuid_list variables have been assigned earlier in the script:

# Check the entries in the file list

while read -r uuid name; do
# Ignore comment lines
   [[ $uuid = \#* ]] && continue
   if [[ -f "${source_directory}/${uuid}*" ]]
   then
      echo "File for ${name} has arrived"
   else
      echo "PANIC! - No File for ${name}"
   fi
done < "${uuid_list}"

How should I check that the files in my list exist in the directory? I'd like to use bash functionality as far as possible, but am not against using commands if need be.

choroba

Walk over the files, create an associative array over the uuids contained in their names (I used parameter expansion to extract the uuid). The, read the list, check the associative array for each uuid and report whether the file was recorded or not.

#!/bin/bash
uuid_list=...

declare -A file_for
for file in *_*_* ; do
    uuid=${file%%_*}
    file_for[$uuid]=1
done

while read -r uuid name ; do
    [[ $uuid = \#* ]] && continue
    if [[ ${file_for[$uuid]} ]] ; then
        echo "File for $name has arrived."
    else
        echo "File for $name missing!"
    fi
done < "$uuid_list"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bash - Check directory for files against list of partial file names

From Java

bash: use list of file names to concatenate matching files across directories and save all files in new directory

From Dev

How to check that the audio files in a directory match the file names stored in a database

From Dev

How to remove files from a directory if their names are not in a text file? Bash script

From Dev

Read in all the files in a particular directory displays the file names in a html list

From Dev

Copying files based on partial names in a file

From Dev

Check for readable files for a directory in bash

From Dev

Check whether files in a file list exist in a certain directory

From Dev

Execute commands against list of items in file in bash

From Dev

Check a PowerShell script line against a txt file containing computer names

From Dev

Return a list of Directory (Folder) names that match a partial string

From Dev

Batch Files: List file names and folder names

From Dev

List names of files in FTP directory and its subdirectories

From Dev

Obtaining file names from directory in Bash

From Dev

Delete files and directories by their names. No such file or directory

From Dev

What is the windows cmd prompt command to -> List 'n' file names in console from a directory having 100 files

From Dev

List file names in order of file size in BASH

From Dev

Select wav files from a folder whose partial names are in a text file

From Dev

How to build a list of file names in a local directory?

From Dev

Inno Setup: List all file names in an directory

From Dev

bash complete: list directory names from a defined directory?

From Dev

bash check all file in a directory for their extension

From Dev

BASH find file names but skip a list of file names

From Dev

Recursively check txt file contents against a list of strings

From Dev

Recursively list files from a given directory in Bash

From Dev

Bash command to get list of files in directory

From Dev

Check / match string against partial strings in array

From Dev

List only file names in directories and subdirectories in bash

From Dev

Bash find line of code in a file/files, in directory

Related Related

  1. 1

    Bash - Check directory for files against list of partial file names

  2. 2

    bash: use list of file names to concatenate matching files across directories and save all files in new directory

  3. 3

    How to check that the audio files in a directory match the file names stored in a database

  4. 4

    How to remove files from a directory if their names are not in a text file? Bash script

  5. 5

    Read in all the files in a particular directory displays the file names in a html list

  6. 6

    Copying files based on partial names in a file

  7. 7

    Check for readable files for a directory in bash

  8. 8

    Check whether files in a file list exist in a certain directory

  9. 9

    Execute commands against list of items in file in bash

  10. 10

    Check a PowerShell script line against a txt file containing computer names

  11. 11

    Return a list of Directory (Folder) names that match a partial string

  12. 12

    Batch Files: List file names and folder names

  13. 13

    List names of files in FTP directory and its subdirectories

  14. 14

    Obtaining file names from directory in Bash

  15. 15

    Delete files and directories by their names. No such file or directory

  16. 16

    What is the windows cmd prompt command to -> List 'n' file names in console from a directory having 100 files

  17. 17

    List file names in order of file size in BASH

  18. 18

    Select wav files from a folder whose partial names are in a text file

  19. 19

    How to build a list of file names in a local directory?

  20. 20

    Inno Setup: List all file names in an directory

  21. 21

    bash complete: list directory names from a defined directory?

  22. 22

    bash check all file in a directory for their extension

  23. 23

    BASH find file names but skip a list of file names

  24. 24

    Recursively check txt file contents against a list of strings

  25. 25

    Recursively list files from a given directory in Bash

  26. 26

    Bash command to get list of files in directory

  27. 27

    Check / match string against partial strings in array

  28. 28

    List only file names in directories and subdirectories in bash

  29. 29

    Bash find line of code in a file/files, in directory

HotTag

Archive