добавил хэлперы для проверки наличия файла и проверки даты модификации даты
This commit is contained in:
parent
0a2e12b784
commit
f93a74941f
22
src/io.sh
22
src/io.sh
@ -2,8 +2,22 @@
|
|||||||
|
|
||||||
filePutContent() {
|
filePutContent() {
|
||||||
local FILE_PATH=$1
|
local FILE_PATH=$1
|
||||||
DIRECTORY_PATH=$(dirname $FILE_PATH)
|
DIRECTORY_PATH=$(dirname "$FILE_PATH")
|
||||||
mkdir -p $DIRECTORY_PATH
|
mkdir -p "$DIRECTORY_PATH"
|
||||||
touch $FILE_PATH
|
touch "$FILE_PATH"
|
||||||
echo $2 >> $FILE_PATH
|
echo "$2" >> "$FILE_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileExists() {
|
||||||
|
if [ -f "$1" ];
|
||||||
|
then
|
||||||
|
echo "1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
fileModifiedOlder() {
|
||||||
|
if [ "$(find "$1" -type f -mtime "$2")" ];
|
||||||
|
then
|
||||||
|
echo "1"
|
||||||
|
fi
|
||||||
|
}
|
@ -2,8 +2,21 @@
|
|||||||
|
|
||||||
. ./io.sh
|
. ./io.sh
|
||||||
|
|
||||||
filePutContent ./temp.txt "Content was added successfuly1"
|
filePutContent ./temp.txt "Content was added successfully1"
|
||||||
filePutContent ./temp.txt "Content was added successfuly2"
|
|
||||||
|
[ "$(fileExists ./temp.txt)" ] && echo "File exists"
|
||||||
|
|
||||||
|
filePutContent ./temp.txt "Content was added successfully2"
|
||||||
|
|
||||||
cat ./temp.txt
|
cat ./temp.txt
|
||||||
unlink ./temp.txt
|
unlink ./temp.txt
|
||||||
|
|
||||||
|
[ ! "$(fileExists ./temp.txt)" ] && echo "File not exists"
|
||||||
|
|
||||||
|
today="$(date +%Y-%m-%d)"
|
||||||
|
nextDate=$(date +%Y-%m-%d -d "$today - 3 days")
|
||||||
|
|
||||||
|
touch -mad "$nextDate 00:00:01" ./temp
|
||||||
|
[ "$(fileModifiedOlder ./temp 3)" ] && echo "File is older 3 days"
|
||||||
|
[ ! "$(fileModifiedOlder ./temp 4)" ] && echo "File is not older 4 days"
|
||||||
|
unlink ./temp
|
Loading…
Reference in New Issue
Block a user