-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxtime
More file actions
executable file
·46 lines (36 loc) · 1001 Bytes
/
Copy pathxtime
File metadata and controls
executable file
·46 lines (36 loc) · 1001 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
#############################################
# author:fang
# version : v1.0
# name : xtime
# dispcripe: use baidu_time set local time
# CopyRight@fangyunjiang[42550564@qq.com]
#############################################
source ~/command/common
function set_beijing_time()
{
local tmp_file time_secs start_time end_time offset_time
tmp_file=._tmp_file_
start_time=$(date '+%s')
wget -O $tmp_file -q "http://open.baidu.com/special/time/"
#iconv -f GB2312 -t UTF-8 .phone_tmp >.phone_tmp_u
time_secs=$($_SED_ '/window.baidu_time([0-9]\+);/!d;s/^.*(\([0-9]\+\)).*/\1/' $tmp_file)
end_time=$(date '+%s')
((offset_time=end_time-start_time))
((time_secs=time_secs/1000+offset_time))
expect -c "
spawn $_SUDO_ date -s @$time_secs
expect {
\"Password:\" {send \"fangyunjiang\r\"}
}
interact
" 2>/dev/null 1>&2
$_RM_ -f $tmp_file
}
function main()
{
__show_progressbar 0.1 set_beijing_time
echo "have set time to baidu time:"
date '+%F %T'
}
main "$@"