You are not logged in.
So I'd like to run the function 'thecode' at more or less exact and each real-clock minute change and this is the horror I came up with:
1.
#!/bin/bash
# waitUntil
# This should run 'thecode' at approximate real-clock minute change.
update() {
# minutes from real clock without 0 padding
oldmin="$(date +%-M)"
newmin="$oldmin"
#echo "$newmin"
}
waitUntil() {
while (( oldmin == newmin ))
do
sleep 1
newmin="$(date +%-M)"
done
}
thecode() {
date +%H%M
}
while true
do
thecode
update
waitUntil
done
Anything better, smaller, simpler, more precise?
Observations:
- With sleep set to 0.3 I'am faster to update than tty-clock.
2.
{ while true ; do date +%H%M ; sleep 0.1 ; done } | uniq
Nice and short, but not sure how to call a function from this.
Last edited by brontosaurusrex (2019-09-26 19:17:14)
Offline
Why would you not use at?
https://linux.die.net/man/1/at
--Ben
BL / MX / Raspbian... and a whole bunch of RHEL boxes. :)
Offline
Dunno, forgot to mention: every minute. An example?
at next minute <<< "echo 'woot'"
seems to echo in background.
Last edited by brontosaurusrex (2019-09-26 19:06:42)
Offline
Oh, every minute? Well then.
--Ben
BL / MX / Raspbian... and a whole bunch of RHEL boxes. :)
Offline
@nobody
I'am sure cron is up to the task, just not sure how to make that work in like interactive terminal? (Just trying to update figlet clock at almost exact minute mark at the moment).
Maybe I'll try version 1b to make it work with some sort of variable granularity (with seconds). For example
if seconds > 50 decrease sleep to 0.3 s (before that can be 10 s).
Last edited by brontosaurusrex (2019-09-26 19:54:03)
Offline
You want the command to execute exactly when the minute changes.
Sounds like a job for cron; but it might not be installed anymore on a systemd system. Systemd timer then?
See this: https://stackoverflow.com/questions/173 … riodically
'watch' also has a '-p' option - it might be precise enough that, if you get the start time right, it will run with "clock precision" from then on?
Offline
Found https://github.com/caronc/datetools, so
1b.
#!/bin/bash
#set -x
# waitUntil2, using https://github.com/caronc/datetools dateblock
# This should run 'thecode' at approximate real-clock minute change.
waitUntil() {
dateblock -n /1
}
thecode() {
date +%H%M | toilet -f 3x3
}
while true
do
thecode
waitUntil
done
Offline
Very nice! The beauty of FOSS - there's a solution to almost everything.
Offline
@nobody
This one ? http://4.bp.blogspot.com/_WgybbNCbhU0/T … ax-red.jpg
In this authoritative work, Linux programming expert Michael Kerrisk provides detailed descriptions of the system calls and library functions that you need in order to master the craft of system programming
3.
Crontab version might be done via some dummy file update.
Last edited by brontosaurusrex (2019-09-30 09:04:44)
Offline
Yes. Definitely a good book.
Examples available online.
http://man7.org/tlpi/code/online/all_fi … apter.html
Ch23
Ch63 see select()
Offline
Arrived at ch02, 'what is a process, what are kernel and user space and ...'.
Offline