Skip to content

Commit

Permalink
check if file to move was modified recently to avoid moving still upl…
Browse files Browse the repository at this point in the history
…oading images
  • Loading branch information
maexled authored Jan 13, 2024
1 parent 7456b92 commit de02442
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions move.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ last=-1;
raffer_last_executed_day=-1

while [ true ]; do
date=$(date --date='+0 hour' +'%m/%d/%Y, %H:%M:%S')
datedir=$(date --date='+0 hour' +'%Y/%m/%d')

if [[ ! -d $DIR/files/$datedir/ ]]
Expand All @@ -38,14 +37,20 @@ while [ true ]; do
for f in $temp/*.jpg; do
if [ -f "$f" ] # does file exist?
then
chown $samba_user $f
# Save pictures at least every new hour in longtime
if [ "$save_longtime_pictures" == "true" ]; then
if [ $(date +%H) -ne $last ]
then
echo "New longtime picture, now $(date +%H), last was $last"
cp $f $DIR/files/raffer/longtime/
last=$(date +%H);
# Check if the file has been modified in the last 5 seconds
current_time=$(date +%s)
file_modified_time=$(stat -c %Y "$f")

if [ $((current_time - file_modified_time)) -gt 5 ]; then
chown $samba_user $f
# Save pictures at least every new hour in longtime
if [ "$save_longtime_pictures" == "true" ]; then
if [ $(date +%H) -ne $last ]
then
echo "New longtime picture, now $(date +%H), last was $last"
cp $f $DIR/files/raffer/longtime/
last=$(date +%H);
fi
fi
fi
num=$((num + 1));
Expand Down

0 comments on commit de02442

Please sign in to comment.