I was wondering if I could get some feedback on my script to grab time from our MDM... I blocked out all of the important stuff. I really appreciate any guidance, since I am long out of practice.
#!/bin/bash
serial=$1
# get last seen value of ipad
lastseen=$(curl -s -X "GET" "https://myairwatchmdm.com/api/mdm/devices/serialnumber/$serial" -H "Authorization: Basic bartsimpson=" -H "aw-tenant-code: marge" | xmllint --format -|grep LastSeen | awk -F "T|<" '{print $3}' | awk -F: '{printf "%1.0f",($1*60)+$2+($3%60)}')
# get UTC time
utc=$(UTC date -j %s)
#get time difference
timediff="$((utc-lastseen))"
# Ipad exit successful
if [[ "$timediff" -eq 0 ]] || [[ "$timediff" -lt 3600 ]];
echo "$timediff"
then exit 0;
# Ipad warning threshhold
elif [[ "$timediff" -gt 3600 && "$timediff" -lt 3701 ]];
echo "$lastseen tablet is reaching warning threshold"
then exit 1;
# Ipad not seen for more then sixty minutes
elif [[ "$timediff" -gt 3600 ]];
echo "$lastseen tablet has not been seen in more then an hour"
then exit 2;
# Ipad serial number invalid
elif [[ "$lastseen" = '^[a-ZA-Z]*$' ]] || [[ -z "$lastseen" ]];
echo "Serial Number Invaild"
then exit 3;
fi
The xml looks like this (I blocked out the sensitive bits) I am using grep to get the last seen value.
LocationGroupName><UserName>myipad</UserName><UserEmailAddress>myipad@myorg.com</UserEmailAddress><Ownership>C</Ownership><PlatformId title="Apple">2</PlatformId><Platform>Apple</Platform><ModelId title="iPad Mini with Retina (16 GB Space Gray)">2</ModelId><Model>iPad Mini with Retina (16 GB Space Gray)</Model><OperatingSystem>11.1.0</OperatingSystem><PhoneNumber /><LastSeen>2017-12-12T16:49:33.863</LastSeen><EnrollmentStatus>Enrolled</EnrollmentStatus><ComplianceStatus>Compliant</ComplianceStatus><CompromisedStatus>false</CompromisedStatus><LastEnrolledOn>2017-11-07T20:21:19.36</LastEnrolledOn><LastComplianceCheckOn>2017-12-12T16:21:29.97</LastComplianceCheckOn><LastCompromisedCheckOn>0001-01-01T00:00:00</LastCompromisedCheckOn><IsSupervised>true</IsSupervised><IsRemoteManagementEnabled>False</IsRemoteManagementEnabled><DataEncryptionYN>N</DataEncryptionYN><AcLineStatus>0</AcLineStatus><VirtualMemory>0</VirtualMemory><OEMInfo>ME276LL</OEMInfo><DeviceCapacity>12.052879333496094</DeviceCapacity><AvailableDeviceCapacity>10.491180419921875</AvailableDeviceCapacity><LastSystemSampleTime>2017-12-12T16:49:35</LastSystemSampleTime><IsDeviceDNDEnabled>false</IsDeviceDNDEnabled><IsDeviceLocatorEnabled>fal
Not sure what you need the NULL test for. Try (provided the date command on your system (the version of either you dodn't mention, btw) allows for it):
That weren't constructive as it would ignore hours, days, months, years. %s is NOT a date's seconds' part, but the total count of seconds from "the epoque". %m , btw, specifies the month.