How to add 15 or 30 or 60 minutes to the time 15:00 PM..?
#!/bin/bash
#the vm shutdown tag
tag="15:00 PM"
#the "/usr/bin/input_azureuser.log" file contains snooze data in minutes
#snooze_time values will be "15,30 or 60" Minutes
snooze_time=`cat /usr/bin/input_azureuser.log |tail -n 1 | awk '{print $8}'`
/usr/bin/input_azureuser.log
:
#azureuser@puppetclient-ubuntu:~$ cat /usr/bin/input_azureuser.log
Mon Sep 6 11:24:14 UTC 2021 azureuser 15
Mon Sep 6 11:36:32 UTC 2021 azureuser 30
Mon Sep 6 13:51:03 UTC 2021 azureuser 15
Mon Sep 6 13:52:31 UTC 2021 azureuser 60
Mon Sep 6 14:41:40 UTC 2021 azureuser 15
If snooze/delay_time value is 15/30/60 minutes I want to add the same values to the tag and update the tag like "15:15 PM" ,"15:30 PM" and "16:00".
You can use the date
command to add relative offsets to dates and times.
date -d"90 minutes 15:00" '+%H:%M'
Where -d
is the time and adjustment, and +...
is the output format. So:
snooze_time=90
tag="15:00"
tag=`date -d"$snooze_time minutes $tag" '+%H:%M'`
would update the tag to 16:30
.
Note: using AM/PM with the 24 hour clock is an error.