[: : integer expression expected if else condition
Hi All,
I am in need of sending a mail on every fourth sunday of month. I have written the script like this Code:
MAILSUBJECT="test mail" integer expression expected error: If I manually specify the date instead of FOURTH_SUNDAY, script gets executed. Kindly let me know, if there is any work around |
there is no "workaround", there's using commands properly ;-)
the string you're getting out of cal has two lines in it, a blank one at the end, so it's not an integer you're getting out of it. I expect there's a better way to get the last month of a month, but my brains switched off for now. If you "head -n1" the output, that'll ditch the blank line. |
This condition identifies the fourth Sunday of the month:
Code:
[[ $(date +%w) -eq 0 && $(date +%d) -ge 22 && $(date +%d) -le 28 ]] |
I tried with head command, but received same error
Code:
MAILSUBJECT="test mail" |
Your last example should work, since it retrieves a single value with no extra lines from the calendar. Anyway, using cal in this way is not a robust method to retrieve the 4th Sunday of the month: for example, compare July and November of this year:
Code:
July 2012 November 2012 Therefore, why not using a more robust method as suggested previously? For example, consider that the 4th Sunday of the month is always included in the week between the 22nd and the 28th of the month, so that: Code:
if [[ $(date +%w) -eq 0 && $(date +%d) -ge 22 && $(date +%d) -le 28 ]] |
All times are GMT -5. The time now is 05:29 AM. |