Get the App
SLTechnology News&Howtos  ›  Servers  › 

Line 40: 09: value too great for base (error token is & quot;09")

Shulou Source: shulou.com Published: 2022-06-02 05:37:19 10月02日 Update

Os:rhel6.8 2.6.32-642.el6.x86_64

Today, the ping test script of the redis database written in the test times made an error ". / redis_ping.sh: line 40: 09: value too great for base (error token is" 09 ")", asked du Niang, said that because the double bracket operator in shell will calculate the number starting with 0 as octal, so it will report an error, 09 is larger than the cardinality. The place where the double-bracketed operator is used in the script is where the date is processed in minutes and seconds, as follows:

Cur_date= `date "+% Y-%m-%d% H:%M:%S" `- get the formatting time

Cur_hour_m2=$ (($((${cur_date:11:2} + 0))% 2))-intercepts the string and adds it to 0 with a double parenthesis operator (to remove the placeholder 0, let,expr and so on are usually used to add 0), but contrary to one's wishes, the double parenthesis operator cannot be calculated as a decimal for a number starting with 0

Cur_min=$ ((${cur_date:14:2} + 0))-- intercept the string and add 0

Cur_sec=$ ((${cur_date:17:2} + 0))-- intercept the string and add 0

Modified to:

Cur_hour=$ (($(date +%-H)% 2))-Modulus 2, that is, the control is executed every 2 hours

Cur_min=$ (date +%-M)

Cur_sec=$ (date +%-S)

The idea of this script is to ping all the servers in the redis cluster every 3 seconds. If there is a problem, write an early warning message. If all are normal, then write an early warning message every 2 hours, which means that the heartbeat of the ping script is normal.

Tags: Parentheses scripts operators operations characters strings information places hours beginnings numbers early warning counterproductive Chinese use that is representatives decimal cardinality ideas data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Redmi MySQL MariaDB