Использование ls и stat [closed]

0
18.04.2018, 12:53
2 ответа

Причина в том, что «stat» не видит полного пути «/volume1/surveillance/@Snapshot/». Он просто видит имя файла. Итак, вам нужно изменить сценарий.

#!/bin/sh
DIR=/volume1/surveillance/@Snapshot
LASTFILE=$(cd $DIR && ls *.jpg  | tail -1)

# Input file

# How many seconds before file is deemed "older"
OLDTIME=3600
# Get current and file times
CURTIME=$(date +%s)
FILETIME=$(stat $DIR/$LASTFILE -c %Y)
TIMEDIFF=$(expr $CURTIME - $FILETIME)

# Check if file older
if [ $TIMEDIFF -gt $OLDTIME ]; then

 echo "No Movement Dectected in Last Hour" ;
 exit 1
fi
0
28.01.2020, 02:43

С GNU findили совместимым:

if
  ! find /volume1/surveillance/@Snapshot -name '*.jpg' -mmin -60 |
    grep -q '^'
then
  echo No movement detected in the last hour
  exit 1
fi

Или сzsh:

last_hour=(/volume1/surveillance/@Snapshot/*.jpg(Nmh-1))
if (($#last_hour = 0)); then
  echo No movement detected in the last hour
  exit 1
fi
1
28.01.2020, 02:43

Теги

Похожие вопросы