functions.sh
2.54 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
################################################################
#@Authro Lijian
#@Date 2007-05-24
#@Description:
# the script is on top level
# check if root run the script
################################################################
#if [ `id -u` = 0 ]
#then
# echo "****************************************************"
# echo "*Error: root (the superuser) can't run this script.*"
# echo "****************************************************"
# exit 1
#fi
cygwin=false
case "`uname`" in
CYGWIN*)
cygwin=true
;;
esac
if [ $cygwin = true ]
then
echo "****************************************************"
echo "*Error: Cygwin shell can't run this script.*********"
echo "****************************************************"
exit 1
fi
if [ -f /etc/sysconfig/init ]; then
. /etc/sysconfig/init
else
SETCOLOR_SUCCESS=
SETCOLOR_FAILURE=
SETCOLOR_WARNING=
SETCOLOR_NORMAL=
fi
success () {
if [ "$BOOTUP" = "color" ]; then
$SETCOLOR_SUCCESS
if [ -z "$*" ]; then
echo "ok"
else
echo -e "$*"
fi
$SETCOLOR_NORMAL
else
if [ -z "$*" ]; then
echo "ok"
else
echo -e "$*"
fi
fi
return
}
failed () {
if [ "$BOOTUP" = "color" ]; then
$SETCOLOR_FAILURE
if [ -z "$*" ]; then
echo "failed"
else
echo -e "$*"
fi
$SETCOLOR_NORMAL
else
if [ -z "$*" ]; then
echo "failed"
else
echo -e "$*"
fi
fi
return
}
warning () {
if [ "$BOOTUP" = "color" ]; then
$SETCOLOR_WARNING
if [ -z "$*" ]; then
echo "warning"
else
echo -e "$*"
fi
$SETCOLOR_NORMAL
else
if [ -z "$*" ]; then
echo "warning"
else
echo -e "$*"
fi
fi
return
}
remove_ipcs () {
pid=$*
who=`whoami`
if [ -z $pid ]; then
warning "Warning: Removed share memory and semaphore--gived pid is NULL"
return
fi
shmids=`ipcs -mp |grep -P "\d+[ ]+$who[ ]+$pid" |awk '{print $1}'`
for id in $shmids ; do
ipcrm -m $id
done
shsemids=`ipcs -sp |grep -P "\d+[ ]+$who[ ]+$pid" |awk '{print $1}'`
for id in $shsemids ; do
ipcrm -s $id
done
}
printProcess() {
times=$*
if [ -z $times ]; then
times=1
fi
for (( i=0; i<$times; i=i+1 ))
do
echo -e ".\c"
sleep 1
done
}