Answer the question
In order to leave comments, you need to log in
How to create a while-do loop in a script to check if the file is empty?
This is my first time writing a script.
You need to create something like this: check the file until it turns out that it exists and is not empty (there will be a certificate in the file)
While [test shows that the file either does not exist or is empty]
Do
Check again if the file exists and is empty file
Done
Tried this, doesn't work:
IsFileEmptyOrMissing(){
file="$1"
[ ! -s "${file}" ] && return 0 || return 1
}
IsFileEmptyOrMissing "ca.crt" >res
Cat res (empty)
x=$(cat res)
while [ $x != 0 ]
Do
IsFileEmptyOrMissing "ca.crt" >res
x=$(cat res)
Done
The file "ca.crt" now definitely exists for the test, it lies in the folder along with the script.
Answer the question
In order to leave comments, you need to log in
check the file until it appears that it exists and is not empty
while [ ! -s "$file" ] ; do sleep 1 ; done
While [test shows file either does not exist or is empty]
Do
Check again if file exists and if file is empty
Done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question