Hi
I'm attempting to write my first bash script to backup weewx. I'm
struggling with the syntax of a condition for a while loop that checks if
weewx has stopped or is still stopping.
I don't really understand the syntax of the example conditions I can find
for various tutorials on using while to create a loop. I cannot find
anywhere an exact example of using 'systemctl is-active' as the condition
for a while loop.
Appreciate any feedback from people more learned than I.
TIA
Here's what I have at the moment. If I run this script when I know weewx
won't be writing to the database, the commands to zip the files into the
backup directory all work OK.
I don't think I want to be copying the database file in the middle of a
write. So I have a separate script with the backup section removed just
trying to test the stopping, check has stopped and start parts of the
script. I've been unsuccessfully futzing around with different condition
syntax and actively trying to run it when weewx is active and the stop
command will take a while to execute while the weewx main loop completes.
But TBH I'm just wandering about in the dark.
```
#!/bin/bash
#
# Stop weewx service
echo $(date): Weewx is stopping >> /var/log/weewx-backup.log
systemctl stop weewx
#
# Check service has stopped
while [ systemctl -q is-active weewx ];
do
sleep 1
echo $(date): Weewx is still stopping >> /var/log/weewx-backup.log
done
echo $(date): Weewx has stopped >> /var/log/weewx-backup.log
#
# Copy files to backup folder
echo $(date): Backup is starting >> /var/log/weewx-backup.log
tar -czvf /mnt/backup/weewx-conf.tar.gz /etc/weewx
tar -czvf /mnt/backup/weewx-db.tar.gz /var/lib/weewx/weewx.sdb
echo $(date): Backup is complete >> /var/log/weewx-backup.log
#
# Start weewx service
systemctl start weewx
echo $(date): Weewx is starting >> /var/log/weewx-backup.log
```
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/weewx-user/df76a922-ace3-44ae-a65a-0a50b6f8fe92n%40googlegroups.com.