Debian Codegraph @

scripts/announce.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # This script is to announce a message on a server automatically
3 # and repeatedly. It is intended for server admin use.
4 # Here is an example:
5 #
6 # announce.sh localhost account password 30 "Attention: Here is an
7 # announcement\nAnd here is another announcement"
8 #
9 # The bnchat program can be obtained from the bnetd package.
10
11 BNCHAT=bnchat
12 PIPE="/tmp/pipe-bnannounce-$$"
13
14
15 cleanupscip-shell shell shell-project 0.0.0 cleanup(). () {
16 killscip-shell system . . kill. -9 "${pid}" 2> /dev/nullscip-shell filesystem . . `/dev/null`.
17 rmscip-shell system . . rm. -f "${PIPE}" 2> /dev/nullscip-shell filesystem . . `/dev/null`.
18 exit 0
19 }
20
21
22 if [scip-shell system . . `[`. -z "$4" ]; then
23 echoscip-shell system . . echo. -e "Usage: $0 server account password interval [msgs] ..."
24 echoscip-shell system . . echo. -e " server server ip or hostname"
25 echoscip-shell system . . echo. -e " account your server account"
26 echoscip-shell system . . echo. -e " password password for your account"
27 echoscip-shell system . . echo. -e " interval time intervals between announce in seconds"
28 echoscip-shell system . . echo. -e " [msgs] messages you want to announce"
29 echoscip-shell system . . echo.
30 echoscip-shell system . . echo. -e "Notes: Your account should have announce or admin permissions"
31 echoscip-shell system . . echo. -e " If interval is zero then bnannounce will only print"
32 echoscip-shell system . . echo. -e " one copy of the announcement."
33 echoscip-shell system . . echo.
34 exit
35 fi
36
37 rmscip-shell system . . rm. -f "${PIPE}"
38 mknodscip-shell system . . mknod. "${PIPE}" p > /dev/nullscip-shell filesystem . . `/dev/null`.
39 if [scip-shell system . . `[`. $? -ne 0 ] ; then
40 echoscip-shell system . . echo. "$0: failed to make pipe file ${PIPE}, check your permissions." >&2
41 exit 1
42 fi
43
44 server="$1"
45 user="$2"
46 pass="$3"
47 interval="$4"
48 shift 4
49 msg="`echoscip-shell system . . echo. -e "$*" | sedscip-shell system . . sed. -e 's/^/\/announce /g'`"
50
51 "${BNCHAT}" < "${PIPE}" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 &
52 pid="$!"
53 trap "eval cleanup" SIGINT SIGQUIT SIGTERM EXIT
54
55 echoscip-shell system . . echo. -e "${user}" > "${PIPE}"
56 echoscip-shell system . . echo. -e "${pass}" > "${PIPE}"
57 echoscip-shell system . . echo. "/join Supportscip-shell filesystem . . `/join Support`." > "${PIPE}"
58
59 while killscip-shell system . . kill. -0 "${pid}" 2> /dev/nullscip-shell filesystem . . `/dev/null`.; do
60 echoscip-shell system . . echo. "/announce ${msg}" > "${PIPE}"
61 if [scip-shell system . . `[`. "${interval}" -lt "1" ]; then
62 exit
63 fi
64 sleepscip-shell system . . sleep. "${interval}"
65 done
66
67 exit