I have a camera which records files every day. These mp4 files always start with yy-mm-dd. I want to write a bash script to search and display and check whether or not there has been a recording today.
I've come up with this so far:
#! /bin/sh
# start met datum weg te schrijven in variable now met notering jj-mm-dd
now=$(date --rfc-3339=date)`
# regels voor Doorbird
cd /srv/dev-disk-by-uuid-89755130-b502-4d16-943d-6ca02a695f09/Cams
cd Doorbird
cd videos
cd OOKJv2iZ0r
cd 8MaU67FrBu80
[ -f "/srv/dev-disk-by-uuid-89755130-b502-4d16-943d-6ca02a695f09/Cams/Doorbird/videos/OOKJv2iZ0r/8MaU67FrBu80/"$now"*" ] && echo "Doorbird OK."
[ ! -f "/srv/dev-disk-by-uuid-89755130-b502-4d16-943d-6ca02a695f09/Cams/Doorbird/videos/OOKJv2iZ0r/8MaU67FrBu80/"$now"*" ] && echo "Doorbird NOK."
but this only displays Doorbird NOK although there are files which start with yy-mm-dd in the above-mentioned folder.
With another camera that sorts files differently I was able to perform a directory search for the date-variable but without the *-wildcard without any problems. The code for that one was:
# regels voor Tuin
cd /srv/dev-disk-by-uuid-89755130-b502-4d16-943d-6ca02a695f09/Cams
cd 6J0091EPAG73D8B
[ -d "/srv/dev-disk-by-uuid-89755130-b502-4d16-943d-6ca02a695f09/Cams/6J0091EPAG73D8B/"$now"" ] && echo "Tuin OK."
[ ! -d "/srv/dev-disk-by-uuid-89755130-b502-4d16-943d-6ca02a695f09/Cams/6J0091EPAG73D8B/"$now"" ] && echo "Tuin NOK."
Here I get Tuin OK when the directory is present or Tuin NOK when it's not.
Clearly I'm missing something here. I tried looking up the wildcard placement throughout this site to no avail.
man findI use it to find files by name and to find files by date.find -L . -name "foo*"I include path in find command.find /mnt/data -type f -name "*~" -printAnd older log files:find /var/log/ -name *.gz* -type f -atime +10 -printYou can use data in file name with wildcard. Better to use labels, not UUIDs. Labels I understand, UUIDs I do not.lsblk -e 7 -o name,fstype,size,fsused,label,partlabel,mountpoint,uuid,partuuidaskubuntu.com/questions/147319/…date --rfc-3339=datereturns "yyyy-mm-dd". For "yy-mm-dd", usedate +%y-%m-%d.