Trigger a command when two files have arrived in different directories in Centos 7
I would create a wrapper script that was called by incrond, something like
if [ -f /dir/path1 -a -f /dir/path2 ]; then
command
else
echo "both files don't exist yet"
fi
This would run every time either file triggered IN_CLOSE_WRITE or IN_MOVED_TO, but would only run when both files were present.
Update
based on the comments, it seem like tracking the completed state of the uploaded file is necessary. (I didn't test the following) The idea is to record the completion of the uploaded file, and
#!/bin/bash
# $@ set to event filename by incrond
filepath=$@
# this assumes both files are in the same directory, otherwise you would
# have to do some logic which switches directories as well as filename
# check file matches pattern
if [[ "${filepath}" =~ vlan.*\.pcap$ ]]; then
# mark current file as completed
if [ ! -f "${filepath}.complete" ]; then
touch "${filepath}.complete"
fi
filename=$(basename ${filepath})
dirname=$(dirname ${filepath})
# find other filename by toggling vlan number
vlan_num=${filename:4:1}
[[ "${vlan_num}" == "1" ]] && vlan_alt=2 || vlan_alt=1
# construct the other filename
other_file=${dirname}$/{filename:0:4}${vlan_alt}${filename:5}
echo $other_file;
# see if other filename completion file exists
if [ -f "${other_file}.complete" ]; then
command
else
# other file not uploaded yet
echo "completion file for both files not exists"
fi
else
echo "file didn't match pattern"
fi