-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix-clock.sh
executable file
·31 lines (27 loc) · 1.04 KB
/
fix-clock.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# Function to fetch time data and update system clock
function fix_clock {
# Function to get time in Philippines and update system clock
get_time_in_philippines() {
# Fetch time data from World Time API
current_time=$(curl -s http://worldtimeapi.org/api/timezone/Asia/Manila | grep -oP '(?<="datetime":")[^"]*')
year=$(date -d "$current_time" +"%Y")
month=$(date -d "$current_time" +"%-m")
day=$(date -d "$current_time" +"%-d")
hour=$(date -d "$current_time" +"%-H")
minute=$(date -d "$current_time" +"%-M")
second=$(date -d "$current_time" +"%-S")
# Set time and date
timedatectl set-time "$year-$month-$day $hour:$minute:$second"
echo "System time and date have been successfully updated."
}
# Check if curl is installed
if command -v curl &>/dev/null; then
get_time_in_philippines
else
echo "Curl not found. Please install curl to use this script."
exit 1
fi
}
# Execute the fix_clock function
fix_clock