update_time.sh:
#!/bin/bash
export SUDO_ASKPASS=/home/mission/update_time/printpwd
HOME_DIR=/home/mission/update_time
LOG_FILE="${HOME_DIR}/update_date.log"
cd $HOME_DIR
n=`ps -ef|grep "update_time.sh"|grep -v grep|wc -l`
if [ $n -gt 2 ]; then
exit 0
fi
ntpips=`cat ip.txt`
interval=300
rm $LOG_FILE
while true;
do
for ip in $ntpips
do
date "+%Y-%m-%d %H:%M:%S" >> $LOG_FILE
sudo -A ntpdate $ip >> $LOG_FILE 2>&1
if [ $? == 0 ]; then
date "+%Y-%m-%d %H:%M:%S" >> $LOG_FILE
sudo -A hwclock --show >> $LOG_FILE 2>&1
sudo -A hwclock -w >> $LOG_FILE 2>&1
[ $? -eq 0 ] && echo "hwclock -w success" >> $LOG_FILE 2>&1
date "+%Y-%m-%d %H:%M:%S" >> $LOG_FILE
sudo -A hwclock --show >> $LOG_FILE 2>&1
break;
fi
done
sleep $interval
done