I'm trying to create a persistent ipset that is regularly backed up with a cron job.
The problem I'm running into is testing whether or not the "ipset restore" restore file exists.
The problem I'm running into is testing whether or not the "ipset restore" restore file exists.
Step 1
Is there a better way to write this ?If the restore file doesn't exist, create the file: /path/LIST.sav with the following contents:
Step 2create LIST hash:ip family inet hashsize 1024 maxelem 65536 timeout 600
If the restore file does exist, run the following command.
Solution:ipset restore < /path/LIST.sav
Code:
if [ -s /path/LIST.sav ]
then
ipset restore < /path/LIST.sav
else
echo 'create LIST hash:ip family inet hashsize 1024 maxelem 65536 timeout 600' > /path/LIST.sav
ipset restore < /path/LIST.sav
fi