Skip to main content
Rollback to Revision 7
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

how do I modify the inotifywait command to report only when a file of certain type/extension is created

Please delete my profile as requestednote that this is untested code since I don't have access to inotify right now. But something akin to this ought to work with bash:

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        if [[ "$file" =~ .*xml$ ]]; then # Does the file end with .xml?
            echo "xml file" # If so, do your thing here!
        fi
    done

Alternatively, without bash,

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        case "$file" in
            (*.xml)
                echo "xml file" # Do your thing here!
                ;;
        esac
        fi
    done

With newer versions of inotifywait you can directly create a pattern match for files:

inotifywait -m /path -e create -e moved_to --include '.*\.xml$' |
    while read -r directory action file; do
        echo "xml file" # Do your thing here!
    done

Please delete my profile as requested.

how do I modify the inotifywait command to report only when a file of certain type/extension is created

Please note that this is untested code since I don't have access to inotify right now. But something akin to this ought to work with bash:

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        if [[ "$file" =~ .*xml$ ]]; then # Does the file end with .xml?
            echo "xml file" # If so, do your thing here!
        fi
    done

Alternatively, without bash,

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        case "$file" in
            (*.xml)
                echo "xml file" # Do your thing here!
                ;;
        esac
        fi
    done

With newer versions of inotifywait you can directly create a pattern match for files:

inotifywait -m /path -e create -e moved_to --include '.*\.xml$' |
    while read -r directory action file; do
        echo "xml file" # Do your thing here!
    done
added 3 characters in body
Source Link
anon
anon

how do I modify the inotifywait command to report only when a file of certain type/extension is created

Please note that this is untested code since I don't have access to inotify right nowdelete my profile as requested. But something akin to this ought to work with bash:

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        if [[ "$file" =~ .*xml$ ]]; then # Does the file end with .xml?
            echo "xml file" # If so, do your thing here!
        fi
    done

Alternatively, without bash,

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        case "$file" in
            (*.xml)
                echo "xml file" # Do your thing here!
                ;;
        esac
        fi
    done

With newer versions of inotifywait you can directly create a pattern match for files:

inotifywait -m /path -e create -e moved_to --include '.*\.xml$' |
    while read -r directory action file; do
        echo "xml file" # Do your thing here!
    done

how do I modify the inotifywait command to report only when a file of certain type/extension is created

Please note that this is untested code since I don't have access to inotify right now. But something akin to this ought to work with bash:

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        if [[ "$file" =~ .*xml$ ]]; then # Does the file end with .xml?
            echo "xml file" # If so, do your thing here!
        fi
    done

Alternatively, without bash,

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        case "$file" in
            (*.xml)
                echo "xml file" # Do your thing here!
                ;;
        esac
        fi
    done

With newer versions of inotifywait you can directly create a pattern match for files:

inotifywait -m /path -e create -e moved_to --include '.*\.xml$' |
    while read -r directory action file; do
        echo "xml file" # Do your thing here!
    done

Please delete my profile as requested.

Rollback to Revision 5
Source Link
Pablo A
  • 3.2k
  • 1
  • 26
  • 46

how do I modify the inotifywait command to report only when a file of certain type/extension is created

Please just delete................note that this is untested code since I don't have access to inotify right now. But something akin to this ought to work with bash:

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        if [[ "$file" =~ .*xml$ ]]; then # Does the file end with .xml?
            echo "xml file" # If so, do your thing here!
        fi
    done

Alternatively, without bash,

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        case "$file" in
            (*.xml)
                echo "xml file" # Do your thing here!
                ;;
        esac
        fi
    done

With newer versions of inotifywait you can directly create a pattern match for files:

inotifywait -m /path -e create -e moved_to --include '.*\.xml$' |
    while read -r directory action file; do
        echo "xml file" # Do your thing here!
    done

Please just delete.................

how do I modify the inotifywait command to report only when a file of certain type/extension is created

Please note that this is untested code since I don't have access to inotify right now. But something akin to this ought to work with bash:

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        if [[ "$file" =~ .*xml$ ]]; then # Does the file end with .xml?
            echo "xml file" # If so, do your thing here!
        fi
    done

Alternatively, without bash,

inotifywait -m /path -e create -e moved_to |
    while read -r directory action file; do
        case "$file" in
            (*.xml)
                echo "xml file" # Do your thing here!
                ;;
        esac
        fi
    done

With newer versions of inotifywait you can directly create a pattern match for files:

inotifywait -m /path -e create -e moved_to --include '.*\.xml$' |
    while read -r directory action file; do
        echo "xml file" # Do your thing here!
    done
deleted 1095 characters in body
Source Link
anon
anon
Loading
added 1 character in body
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323
Loading
make script more compatible across shells
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323
Loading
Replace "path" local variable for case insensitive shells
Source Link
Loading
Source Link
anon
anon
Loading