Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

'date' issue [solved by reinob]

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
User avatar
ksu
Posts: 79
Joined: 2014-01-13 14:59
Has thanked: 3 times
Been thanked: 1 time

'date' issue [solved by reinob]

#1 Post by ksu »

Hello,

I noticed a strange behavior with one of the daily cron, "single-liners" i got running for past several months:

Code: Select all

EVENODD="$([ $(($(date +%d)%2)) -eq 0 ] && echo "EVEN" || echo "ODD")"
tar czf /root/etc.backup.daily$EVENODD.tar.gz /etc &> /tmp/etc.backup.daily$EVENODD.log
it created the backups yesterday, and the day before ( 7th and 6th of Mar ):

Code: Select all

-rw-r--r--  1 root root 1244662 Mar  6 02:55 etc.backup.dailyEVEN.tar.gz
-rw-r--r--  1 root root 1244665 Mar  7 02:55 etc.backup.dailyODD.tar.gz
but today at 2:55am it failed with:

Code: Select all

 08: value too great for base (error token is "08")

Code: Select all

$ echo $(($(date +%d)%2))
started suddenly failing... not only on the Jessie, but on Gentoo, and Stretch.

The script has not been modified for a while... if it would fail earlier, the result tars would not get created as shown, unless I am going crazy...

Thanks,

Mike
Last edited by ksu on 2017-03-08 17:27, edited 2 times in total.
"They did not know it was impossible so they did it” - Mark Twain

reinob
Posts: 1196
Joined: 2014-06-30 11:42
Has thanked: 99 times
Been thanked: 47 times

Re: 'date' issue

#2 Post by reinob »

ksu wrote:Hello,

I noticed a strange behavior with one of the daily cron, "single-liners" i got running for past several months:

Code: Select all

EVENODD="$([ $(($(date +%d)%2)) -eq 0 ] && echo "EVEN" || echo "ODD")"
tar czf /root/etc.backup.daily$EVENODD.tar.gz /etc &> /tmp/etc.backup.daily$EVENODD.log
it created the backups yesterday, and the day before ( 7th and 6th of Mar ):

Code: Select all

-rw-r--r--  1 root root 1244662 Mar  6 02:55 etc.backup.dailyEVEN.tar.gz
-rw-r--r--  1 root root 1244665 Mar  7 02:55 etc.backup.dailyODD.tar.gz
but today at 2:55am it failed with:

Code: Select all

 08: value too great for base (error token is "08")

Code: Select all

$ echo $(($(date +%d)%2))
started suddenly failing... not only on the Jessie, but on Gentoo, and Stretch.

The script has not been modified for a while... if it would fail earlier, the result tars would not get created as shown, unless I am going crazy...

Thanks,

Mike
My bet: 08 is being interpreted as octal (because it starts with zero). On Friday you'll be fine again :)

User avatar
ksu
Posts: 79
Joined: 2014-01-13 14:59
Has thanked: 3 times
Been thanked: 1 time

Re: 'date' issue

#3 Post by ksu »

hehe, great...

[edit]
disregard these next lines, you still can do modulo in octal base

i also did:

Code: Select all

gentoo3 ~ # echo $(($(date +%d)%2))
-bash: 08: value too great for base (error token is "08")
gentoo3 ~ # date -s "7 Mar 2017 2:55:00"
Tue Mar  7 02:55:00 EST 2017
gentoo3 ~ # echo $(($(date +%d)%2))
1
gentoo3 ~ # date -s "6 Mar 2017 2:55:00"
Mon Mar  6 02:55:00 EST 2017
gentoo3 ~ # echo $(($(date +%d)%2))
0
Last edited by ksu on 2017-03-08 17:26, edited 1 time in total.
"They did not know it was impossible so they did it” - Mark Twain

reinob
Posts: 1196
Joined: 2014-06-30 11:42
Has thanked: 99 times
Been thanked: 47 times

Re: 'date' issue

#4 Post by reinob »

ksu wrote:hehe, great...

i also did:

Code: Select all

gentoo3 ~ # echo $(($(date +%d)%2))
-bash: 08: value too great for base (error token is "08")
gentoo3 ~ # date -s "7 Mar 2017 2:55:00"
Tue Mar  7 02:55:00 EST 2017
gentoo3 ~ # echo $(($(date +%d)%2))
1
gentoo3 ~ # date -s "6 Mar 2017 2:55:00"
Mon Mar  6 02:55:00 EST 2017
gentoo3 ~ # echo $(($(date +%d)%2))
0
http://wiki.bash-hackers.org/syntax/ari ... rent_bases

User avatar
ksu
Posts: 79
Joined: 2014-01-13 14:59
Has thanked: 3 times
Been thanked: 1 time

Re: 'date' issue

#5 Post by ksu »

yup, that explains! Thank you!
"They did not know it was impossible so they did it” - Mark Twain

User avatar
ksu
Posts: 79
Joined: 2014-01-13 14:59
Has thanked: 3 times
Been thanked: 1 time

Re: 'date' issue [solved]

#6 Post by ksu »

changed %d to %e

thanks again!!!!
"They did not know it was impossible so they did it” - Mark Twain

Post Reply