Forum Discussion
Looking to find clock time minus 30 seconds
- Jul 13, 2015
I will start by saying that many authentication systems rely on accurately synchronized clocks in order to avoid replay messages, and I suspect Google Authenticator is the same. As such, it is better to have clients and servers that both use NTP.
Having said that: the square brackets are an evaluation operator. The command inside the operators are evaluated in-place. If you pass [clock seconds - 30], then Tcl will try to execute the command clock and pass it three parameters, namely: seconds, -, and 30. You don't want that. Instead, you want to force arithmetic evaluation using expr, which treats parameters as a series of operators. So, this is what you're looking for:
set time [binary format W* [expr { ([clock seconds] - 30) / 30 }]
Notice that you must use parentheses to force the order of evaluation (subtraction first, then division), as is required by normal algebraic rules. Also notice the squirly brackets for the expr command. They are not strictly required, but are always recommended to avoid double-evaluation.
Incidentally, since you grab clock seconds first, then the following provides the same outcome:
set cs [expr { [clock seconds] / 30 }] set time [binary format W* $cs] set css [incr cs -1]
That is, css will be the equivalent of your formula, but is simpler to compute.
I will start by saying that many authentication systems rely on accurately synchronized clocks in order to avoid replay messages, and I suspect Google Authenticator is the same. As such, it is better to have clients and servers that both use NTP.
Having said that: the square brackets are an evaluation operator. The command inside the operators are evaluated in-place. If you pass [clock seconds - 30], then Tcl will try to execute the command clock and pass it three parameters, namely: seconds, -, and 30. You don't want that. Instead, you want to force arithmetic evaluation using expr, which treats parameters as a series of operators. So, this is what you're looking for:
set time [binary format W* [expr { ([clock seconds] - 30) / 30 }]
Notice that you must use parentheses to force the order of evaluation (subtraction first, then division), as is required by normal algebraic rules. Also notice the squirly brackets for the expr command. They are not strictly required, but are always recommended to avoid double-evaluation.
Incidentally, since you grab clock seconds first, then the following provides the same outcome:
set cs [expr { [clock seconds] / 30 }]
set time [binary format W* $cs]
set css [incr cs -1]
That is, css will be the equivalent of your formula, but is simpler to compute.
- Rosieodonell_16Jul 13, 2015
Cirrus
This is the error that i am getting: 01070151:3: Rule [/Common/google_auth_verify_apm_2] error: /Common/google_auth_verify_apm_2:103: error: [parse error: missing close-bracket][[binary format W* [expr { ([clock seconds] - 30) / 30 }] - Rosieodonell_16Jul 13, 2015
Cirrus
this fixed it: set time [binary format W* [expr { ([clock seconds] - 30) / 30 }]]
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com