14,974
edits
(→BASH) |
|||
| Line 68: | Line 68: | ||
Tested on {{Linux}} & {{Mac}}<ref>[https://bash.cyberciti.biz/guide/Perform_arithmetic_operations Perform arithmetic operations - Linux Shell Scripting Tutorial - A Beginner's handbook]</ref> | Tested on {{Linux}} & {{Mac}}<ref>[https://bash.cyberciti.biz/guide/Perform_arithmetic_operations Perform arithmetic operations - Linux Shell Scripting Tutorial - A Beginner's handbook]</ref> | ||
=== Approach1: sleep === | |||
<pre> | <pre> | ||
# print current date & time | # print current date & time | ||
| Line 75: | Line 76: | ||
timeout=$(($RANDOM * 60 / 32768 + 5)) | timeout=$(($RANDOM * 60 / 32768 + 5)) | ||
sleep $timeout | sleep $timeout | ||
# print current date & time | |||
echo $(date '+%Y-%m-%d %H:%M:%S') | |||
</pre> | |||
=== Approach2: ping === | |||
ping local address: {{kbd | key=<nowiki>-c <count></nowiki>}} "Stop after sending (and receiving) count ECHO_RESPONSE packets."<ref>[https://linux.die.net/man/8/ping ping(8) - Linux man page]</ref> | |||
<pre> | |||
# print current date & time | |||
echo $(date '+%Y-%m-%d %H:%M:%S') | |||
# sleep 5 ~ 65 seconds | |||
timeout=$(($RANDOM * 60 / 32768 + 5)) | |||
ping 127.0.0.1 -c $timeout > nul | |||
# print current date & time | # print current date & time | ||