I am trying to do ssh to a remote machine and get list of directory names present at pathA(/home/abc/mydata) which has any file that has been modified in last 1 hours.
-> Directory a
->file1 last modified 1 hour back
->file2 last modified 1 year back
->file3 last modified 1 day back
-> Directory b
->file11 last modified 1 year back
->file22 last modified 1 year back
->file33 last modified 1 year back
->fileb1-11 last modified 1 hour back
-> Directory c
->file111 last modified 1 year back
->file222 last modified 1 year back
->file333 last modified 1 year back
a => as it has 1 file which was modified 1 hour back(file1)
b => as it has 1 file under sub directory of directory b (fileb1-11)
ssh "host" -t "find /home/abc/mydata -type d -mmin -60 -ls"
ssh "$host" ' find /home/abc/mydata -mindepth 1 -maxdepth 1 -type d | while read -r d; do [ "$(find "$d" -mmin -1 -type f -print -quit 2>/dev/null)" ] && ls -ldi "$d" done '
maxdepth, the first
findwill look only at level 1.
findwill look inside each subfolder for regular files (
-type f) recently modified. If other recently modified file types (subdirectories/sockets/symlinks) should trigger the output, remove
sshis only necessary if you want colorized
ls -ldi ...is slightly different from that of
find ... -ls, but I'm guessing it will do.
findis too vague to use here. Instead, we simply test if its output is nonempty.