Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting the time on an AP9606 remotely. #3

Closed
fnarfbargle opened this issue Mar 21, 2020 · 1 comment · Fixed by #4
Closed

Setting the time on an AP9606 remotely. #3

fnarfbargle opened this issue Mar 21, 2020 · 1 comment · Fixed by #4
Assignees
Labels
good first issue Good for newcomers

Comments

@fnarfbargle
Copy link

fnarfbargle commented Mar 21, 2020

This might be of interest. I run this script once a day. It queries the card for the date and if it doesn't match, sets the date and time. It also runs regardless once a month just to keep the clock in check.

I had 2 cards with flat "Snaphat" batteries, so they needed a clock set not infrequently. Now it's just run to save me thinking about it. Replaced one with an P9617 and it has ntp, so the loop is still there.

#!/bin/bash
# Won't set while web user or shell user logged in.

DATE=date +%m/%d/%Y
DAY=date +%d

# Set the clock if the date doesn't match or it's the first of the month.
# The RTC does drift slightly, so this keeps it on track

for i in 192.168.2.231 ; do
IND=snmpwalk -v1 -cpublic $i 1.3.6.1.4.1.318.2.1.6.1 | cut -f2 -d'"'
if [ "$IND" != "$DATE" -o "$DAY" -eq 1 ] ; then
echo Dates don't match or 1st of the month
snmpset -cprivate -v1 $i 1.3.6.1.4.1.318.2.1.6.1.0 s "$DATE" > /dev/null
TIME=date +%H:%M:%S
snmpset -cprivate -v1 $i 1.3.6.1.4.1.318.2.1.6.2.0 s "$TIME" > /dev/null
fi;
done;

Sorry, I completely munged the formatting and have no idea how to fix the quoted bits. Anyway, you get the idea. SNMP works just fine for setting the clock.

@danielewood danielewood self-assigned this Apr 10, 2020
@danielewood danielewood added the good first issue Good for newcomers label Apr 10, 2020
@danielewood danielewood linked a pull request Apr 10, 2020 that will close this issue
@danielewood
Copy link
Owner

Thanks for this, I have added the relevant information to the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants