I have written a simple bash script named write-date.sh
which simply writes the date to a file:
#!/bin/bash
echo "$(date) Write Done" >> write-date.log
And I am running the bash script every 60 seconds like this:
watch -n 60 ./write-date.sh
However when I run the command, the output produced in the write-date.log
file contains output like in the snippet here:
Thu 1 Jul 09:42:03 BST 2021 Write Done
Thu 1 Jul 09:42:03 BST 2021 Write Done
Thu 1 Jul 09:42:03 BST 2021 Write Done
Thu 1 Jul 09:42:03 BST 2021 Write Done
Thu 1 Jul 09:42:03 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:42:04 BST 2021 Write Done
Thu 1 Jul 09:43:04 BST 2021 Write Done
Thu 1 Jul 09:43:26 BST 2021 Write Done
Thu 1 Jul 09:44:26 BST 2021 Write Done
Thu 1 Jul 09:45:26 BST 2021 Write Done
Thu 1 Jul 09:46:26 BST 2021 Write Done
Thu 1 Jul 09:47:26 BST 2021 Write Done
Thu 1 Jul 09:48:26 BST 2021 Write Done
As can be seen, there are times where the date is written to the log file more than once per minute (at 09:42 and 09:43 in this sample snippet) and I can't see why this might be... is the watch command wrong? Is the bash script itself wrong? Is there a system clock issue somewhere?
The os is Ubuntu 20.04 where uname -a
is:
Linux machine 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
I should also point out that the reason for this script is that I am having an issue where the os' root filesystem goes into read-only mode every few hours or sometimes every few days and so I am trying to find out the day and time when this happens so I can later look in /var/log/syslog
around that time to see if anything odd had happened to the system at said time.
--- UPDATE ---
Have stopped running command and cleared log file and re-run command again from scratch and now the date is logged once per minute as one would expect.
As pointed out in comments, the duplicate logs printed may have been from a previous dodgy script run (probably user error) but I can't think how or when this might have happened. Will keep running for hours/days anyway so will keep an eye on it.