Hello, so basically i have a txt file containing "foto's" named YYYY-MM-DD_HH.mm.ss.jpeg.
But since it can probably not convert it it changes the date to the current date. What am i doing wrong?
#!/bin/bash
inputDateFmt()
{
sed -e 's/_/ /g' -e 's/\./:/g' <<< "$1"
}
begindatum=$(date -u -d "$(inputDateFmt "2014-10-27_08.01.01")")
einddatum=$(date -u -d "$(inputDateFmt "2014-10-27_18.00.01")")
while [ "$begindatum" != "$einddatum" ]
do
bestandnaam=$(date --date="$begindatum" +"%Y-%m-%d_%H.%M.%S.jpeg")
if [ $(grep -Fx "$bestandnaam" fotos.txt) ]
then
echo "$bestandnaam found"
else
echo "$bestandnaam not found"
fi
begindatum=$(LC_ALL=C date --utc --iso-8601=seconds -d"$begindatum"+1minute)
done
This is the error i'm getting (basically it is saying that it is a invalid date)
It looks ok, except LC_ALL=C date --utc --iso-8601=seconds -d"$begindatum"+1minute returns something that will never match einddatum (at least, on my machine).
Run it with bash -x script.sh and check what the date commands are actually doing.
Not sure I fully understand what you're doing and what you're after, but a few comments:
Why do you use (convert to) date formats like Mon Oct 27 18:00:01 CET 2014 when the date/time part of your file names is YYYY-MM-DD_HH.mm.ss , i.e. totally different?
info date :
Why do you convert "_" chars to " " and "." to ":" if you dont use those afterwards?
Why do you specify the time stamps down to the second but iterate the loop in one minute steps only?
Would it be feasible to do all the looping, calculating etc. on seconds since epoque, and then convert those to a time string for the comparison / grep ping? Would it make sense to forgo the seconds when grep ping?
And, in lieu of the sed invocation in inputDateFmt , did you consider bash 's "Parameter Expansion: Pattern substitution"?