Hello,
I am new to shell scripting and getting the error "arithmetic syntax error" on line 55 of my script.
Below is line 55 and 56
Backup=$ (( $Year*365+$Day ))
if [[ $PrevHostname = '' ]] then PrevHostname=$Hostname; PrevBackup=$Backup
Error:
./mksysbChk.ksh: line 56: *365+as : arithmetic syntax error
Any help to fix this will be appreciated.
Thanks,
rdrtx1
October 5, 2016, 4:31pm
2
(( Backup = Year * 365 + Day ))
Sorry, I did not get that. Remove the $ signs and include Backup with the brackets?
---------- Post updated at 03:51 PM ---------- Previous update was at 03:34 PM ----------
After the suggested edit; I get the below error
syntax error at line 56: `((' unexpected
You can't have a space between the $ and the (( . So, change:
Backup=$ (( $Year*365+$Day ))
to:
Backup=$(( $Year*365+$Day ))
Inside an arithmetic expansion (i.e., $((expression)) ), shell variable expansions that expand to numeric strings can be specified using $variable_name or variable_name , so the above can also be specified as:
Backup=$(( Year*365+Day ))
and get the same results.
RudiC
October 5, 2016, 4:59pm
5
The *365+as in the error message is a bit suspect. What be the contens of $Day ?
rdrtx1
October 5, 2016, 5:00pm
6
let Backup=$Year*365+$Day
Day=`date|cut -c9-10` # into Month(Mmm), Day(##) & Year(##)
---------- Post updated at 04:06 PM ---------- Previous update was at 04:02 PM ----------
Backup=$Year*365+$Day works. Thanks
However, I get an email failure message;
Final-Recipient: RFC822; hasn318@****.com
Action: failed
Status: 5.0.0
Diagnostic-Code: SMTP; 550 Not permitted
Last-Attempt-Date: Wed, 5 Oct 2016 17:03:40 -0400
hasn318:
Day=`date|cut -c9-10` # into Month(Mmm), Day(##) & Year(##)
---------- Post updated at 04:06 PM ---------- Previous update was at 04:02 PM ----------
Backup=$Year*365+$Day works. Thanks
However, I get an email failure message;
Final-Recipient: RFC822; hasn318@****.com
Action: failed
Status: 5.0.0
Diagnostic-Code: SMTP; 550 Not permitted
Last-Attempt-Date: Wed, 5 Oct 2016 17:03:40 -0400
The email diagnostic shown above has absolutely nothing to do with any of the code you have shown us in this thread.
RudiC
October 6, 2016, 3:20am
9
Don't rely on your Day variable containing a correct number:
date|cut -c9-10
0
/bin/date|cut -c9-10
t
/bin/date -R|cut -c9-10
Oc
calculate day using date +%d
$ day=$(date +%d)
$ echo ${day#0}
6
RudiC
October 6, 2016, 3:55am
11
Seems like the month is missing in your backup calculation, so identical values will repeat 12 times a year...