-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_crontab.sh
50 lines (37 loc) · 1002 Bytes
/
set_crontab.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ksh
#
#set crontab on linux and AIX
#
typeset SN=$(hostname)
export TZ=BEIST-8
function get_time { date +%Y-%m-%d' '%T; }
function set_crontab {
if [ `whoami` != "root" ]; then
echo "Please run as root"
exit
fi
# check if crontab has been set
if [[ ! -z $(crontab -l 2>/dev/null|grep "/usr/local/scripts/wasstat/colWasStats.sh") ]]
then
echo "crontab has been set already"
return
fi
cd /usr/local/scripts/wasstat/
# backup crontab first
typeset fname="crontab.sav.$(date +%Y%m%d.%H%M%S)"
typeset newcronfile="crontab.new"
crontab -l >$fname 2>/dev/null
cp $fname $newcronfile
function echo_content {
echo "#"
echo "# collect WAS performance data @$(get_time)"
echo "#"
echo "0 * * * * /bin/sh /usr/local/scripts/wasstat/colWasStats.sh 1>/dev/null 2>&1"
}
echo_content >> $newcronfile
crontab $newcronfile
}
function main {
set_crontab
}
main