'date' issue [solved by reinob]

If none of the more specific forums is the right place to ask

'date' issue [solved by reinob]

Postby ksu » 2017-03-08 16:11

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.
User avatar
ksu
 
Posts: 40
Joined: 2014-01-13 14:59

Re: 'date' issue

Postby reinob » 2017-03-08 16:22

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 :)
reinob
 
Posts: 490
Joined: 2014-06-30 11:42

Re: 'date' issue

Postby ksu » 2017-03-08 16:25

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.
User avatar
ksu
 
Posts: 40
Joined: 2014-01-13 14:59

Re: 'date' issue

Postby reinob » 2017-03-08 16:27

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
reinob
 
Posts: 490
Joined: 2014-06-30 11:42

Re: 'date' issue

Postby ksu » 2017-03-08 17:05

yup, that explains! Thank you!
User avatar
ksu
 
Posts: 40
Joined: 2014-01-13 14:59

Re: 'date' issue [solved]

Postby ksu » 2017-03-08 17:13

changed %d to %e

thanks again!!!!
User avatar
ksu
 
Posts: 40
Joined: 2014-01-13 14:59


Return to General Questions

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable