/[cvs]/eggdrop1.6/scripts/autobotchk
ViewVC logotype

Annotation of /eggdrop1.6/scripts/autobotchk

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (hide annotations) (download)
Fri Apr 13 19:19:14 2001 UTC (18 years, 7 months ago) by guppy
Branch: MAIN
CVS Tags: eggdrop1_6_5, eggdrop1_6_6
Changes since 1.4: +34 -5 lines
added ITE's weed.patch, also modified weed and autobotchk slighty, sorry for not sending a patch

1 fabian 1.2 #! /bin/sh
2 guppy 1.5 # This trick is borrowed from Tothwolf's Wolfpack \
3     # Search for tclsh[0-9].[0-9] in each valid dir in PATH \
4     for dir in $(echo $PATH | sed 's/:/ /g'); \
5     do \
6     if test -d $dir; \
7     then \
8     files=$(/bin/ls $dir | egrep '^tclsh[0-9]\.[0-9]$'); \
9     if test "$files" != ""; \
10     then \
11     versions="${versions:+$versions }$(echo $files | sed 's/tclsh//g')"; \
12     fi; \
13     fi; \
14     done; \
15     for ver in $versions; \
16     do \
17     tmpver=$(echo $ver | sed 's/\.//g'); \
18     if test "$lasttmpver" != ""; \
19     then \
20     if test "$tmpver" -gt "$lasttmpver"; \
21     then \
22     lastver=$ver; \
23     lasttmpver=$tmpver; \
24     fi; \
25     else \
26     lastver=$ver; \
27     lasttmpver=$tmpver; \
28     fi; \
29     done; \
30     exec tclsh$lastver "$0" "$@"
31 segfault 1.1 #
32     # AutoBotchk, (C)1999 Jeff Fisher (guppy@eggheads.org)
33     #
34     # updates
35     # -------
36     # 03Feb99: wrote the first version and it worked
37     # 04Feb99: made it easier to use, how? ./autobotchk
38     # <config> will create the botchk and crontab
39     # automatically, no command line options now.
40     # 20Feb99: added a '-noemail' setting for [s]
41     # 21Feb99: added '-5' '-10' '-15' '-30' to allow people to
42     # use a diff time value then 10 minutes.
43     # 10May99: to be compatible, don't use */XX's, etc (Ernst)
44 fabian 1.3 # 23Oct99: updated the internal botchk to reflect Tothwolf's
45     # changes in the eggdrop copy.
46 guppy 1.5 # 13Apr01: borrowed code from Tothwolf's Wolfpack to find tclsh
47     # better
48 segfault 1.1 #
49 guppy 1.5 # $Id: autobotchk,v 1.4 1999/12/21 17:35:07 fabian Exp $
50 fabian 1.4 #
51 segfault 1.1 # how to use
52     # ----------
53     # well, first you need to put the program into your Eggdrop
54     # directory (the one you run from hopefully). then you should
55     # probably type 'chmod u+x autobotchk' so the file permissions
56     # are set correctly. and finally, type './autobotchk <config>'
57     # replacing <config> with the name of your config file right?
58     #
59     # in 1.05z, because of [z], you can now specify the bot directory
60     # to use, for example, './autobotchk eggdrop.conf -dir /home/bot'
61     # this now allows you to run the program from any dir :P~
62     #
63     # other Stuff
64     # -----------
65     # [22:36] <cHr|s`> when you type ./autobotchk without any options, it should give you the menu
66     # [22:36] <cHr|s`> like the nukes do
67     # ^ -- he might be Urkel, but we love him anyways ..
68     # [18:10] <[z]> nope...came back weith can't crontab -l error
69     # ^ -- no one said this script was perfect, mmmm z's wife
70     # [19:27] <[z]> also guppy..would be nice if i could reference my bots directories ;)
71     # ^ -- just when I finished 1.05 :P
72     # [18:50] <[s]> how to set the autobotchk not to recieve e-mails about the cron ??
73     # [18:51] <slennox> add >/dev/null 2>&1 to the end of the crontab entry
74     # [18:52] <[s]> what crontab
75     # [18:52] <[s]> i have gupy's script
76     # [18:52] <[s]> autobotchk
77    
78     if {$argc == 0} {
79     puts "\nusage: $argv0 <eggdrop config> \[options\]"
80     puts " -dir (bot directory to use instead of \[pwd\])"
81     puts " -noemail (will make crontab not mail you)"
82     puts " -5 (5 minute checks)"
83     puts " -10 (10 minute checks)"
84     puts " -15 (15 minute checks)"
85     puts " -30 (30 minute checks)\n\n"
86     exit
87     } {
88 guppy 1.5 puts "\nAutoBotchk 1.08, (C)1999 Jeff Fisher (guppy@eggheads.org)"
89 segfault 1.1 puts "----------------------------------------------------------"
90    
91     set x [join [lindex [split $argv] 0]]
92     set q [lrange $argv 1 end]
93     set dir [pwd]
94     set delay 10
95     set email 1
96     for {set z 0} {$z < [llength $q]} {incr z} {
97     set opt [join [lindex $q $z]]
98     switch -- $opt {
99     -time -
100     -1 {set delay 1}
101     -5 {set delay 5}
102     -10 {set delay 10}
103     -15 {set delay 15}
104     -20 {set delay 20}
105     -30 {set delay 30}
106     -nomail -
107     -noemail {set email 0}
108     -dir {
109     set dir [string trimright [join [lindex $q [expr $z + 1]]] /]
110     if {[string match -* $dir]} {
111     puts " *** ERROR: you did not supply a directory name\n\n"
112     exit
113     }
114     if {![file isdirectory $dir]} {
115     puts " *** ERROR: the directory you supplied is not a directory\n\n"
116     exit
117     }
118     incr z
119     }
120     }
121     }
122     switch -- $delay {
123     30 { set minutes "0,30" }
124     15 { set minutes "0,15,30,45" }
125     5 { set minutes "0,5,10,15,20,25,30,35,40,45,50,55" }
126     1 { set minutes "*" }
127     default { set minutes "0,10,20,30,40,50" }
128     }
129     if {![file exists $dir/$x]} {
130     puts " *** ERROR: you supplied a non-existant filename\n\n"
131     exit
132     } elseif {![file isfile $dir/$x]} {
133     puts " *** ERROR: unknown filetype, config files should be text files\n\n"
134     exit
135     } elseif {![file readable $dir/$x]} {
136     puts " *** ERROR: unable to open the file, permission denied\n\n"
137     exit
138     } elseif {![file exists $dir/help] || ![file isdirectory $dir/help]} {
139     puts " *** ERROR: are you sure you are running from a bot directory?\n\n"
140     exit
141     } elseif {![file exists $dir/eggdrop]} {
142     puts " *** ERROR: are you sure you are running from a bot directory?\n\n"
143     exit
144     }
145     puts " *** Attempting to process '$x', be patient ..."
146    
147     set f [open $dir/$x r]
148     while {![eof $f]} {
149     set z [split [gets $f]]
150     if {[join [lindex $z 0]] != "set"} {continue}
151     switch -- [join [lindex $z 1]] {
152     nick -
153     userfile -
154     botnet-nick {
155     set [join [lindex $z 1]] [join [lindex $z 2]]
156     puts " !! scanned: [join $z]"
157     }
158     }
159     }
160     close $f
161     if {![info exists {botnet-nick}] && [info exists nick]} {
162     puts " !! setting \$botnet-nick to \$nick"
163     set botnet-nick $nick
164     }
165     if {![info exists {botnet-nick}] || ![info exists userfile]} {
166     puts " *** ERROR: could not find either \$userfile or \$botnet-nick"
167     puts " !! you sure its a valid Eggdrop config file?\n\n"
168     exit
169     }
170     if {[catch {open $dir/${botnet-nick}.botchk w} fd]} {
171     puts " *** ERROR: unable to open '${botnet-nick}.botchk' for writing"
172     puts " !! without this, this program is useless\n\n"
173     exit
174     }
175 fabian 1.3 puts $fd "
176     #! /bin/sh
177     #
178     # new botchk (for eggdrop 1.1+)
179     #
180     # Created on: [clock format [clock seconds] -format "%B %d, %Y @ %I:%M%p"]
181 guppy 1.5 # Created by: AutoBotchk 1.08 (C)1999 Jeff Fisher
182 fabian 1.3 #
183     # This is a script suitable for use in a crontab. It checks to make sure
184     # your bot is running. YOU NEED A SEPARATE CRON JOB FOR EACH BOT. If your
185     # bot isn't found, it'll try to start it back up.
186     #
187     # You'll need to edit this script for your bot.
188     #
189     # To check for your bot every 10 minutes, put the following line in your
190     # crontab:
191     # 0,10,20,30,40,50 * * * * /home/mydir/botchk
192     # And if you don't want to get email from crontab when it checks you bot,
193     # put the following in your crontab:
194     # 0,10,20,30,40,50 * * * * /home/mydir/botchk >/dev/null 2>&1
195     #
196    
197     # change this to the directory you run your bot from:
198     botdir=\"$dir\"
199    
200     # change this to the name of your bot's script in that directory:
201     botscript=\"eggdrop $x\"
202    
203     # change this to the nickname of your bot (capitalization COUNTS)
204     botname=\"${botnet-nick}\"
205    
206     # change this to the name of your bot's userfile (capitalization COUNTS)
207     userfile=\"$userfile\"
208    
209     ########## you probably don't need to change anything below here ##########
210    
211     cd \$botdir
212    
213     # is there a pid file?
214     if test -r pid.\$botname
215     then
216     # there is a pid file -- is it current?
217     botpid=`cat pid.\$botname`
218     if `kill -CHLD \$botpid >/dev/null 2>&1`
219     then
220     # it's still going -- back out quietly
221     exit 0
222     fi
223     echo \"\"
224     echo \"Stale pid.\$botname file, erasing...\"
225     rm -f pid.\$botname
226     fi
227    
228     if test -r CANTSTART.\$botname
229     then
230     if test -r \$userfile || test -r \$userfile~new || test -r \$userfile~bak
231     then
232     echo \"\"
233     echo \"Userfile found, removing check file 'CANTSTART.\$botname'...\"
234     rm -f CANTSTART.\$botname
235     fi
236     fi
237    
238     # test if we have run botchk previously and didn't find a userfile
239     if test ! -f CANTSTART.\$botname
240     then
241     echo \"\"
242     echo \"Couldn't find bot '\$botname' running, reloading...\"
243     echo \"\"
244     # check for userfile and reload bot if found
245     if test -r \$userfile
246     then
247     # It's there, load the bot
248     ./\$botscript
249     exit 0
250     else
251     if test -r \$userfile~new
252     then
253     # Bot f*@!ed up while saving the userfile last time. Move it over.
254     echo \"Userfile missing. Using last saved userfile...\"
255     mv -f \$userfile~new \$userfile
256     ./\$botscript
257     exit 0
258     else
259     if test -r \$userfile~bak
260     then
261     # Userfile is missing, use backup userfile.
262     echo \"Userfile missing. Using backup userfile...\"
263     cp -f \$userfile~bak \$userfile
264     ./\$botscript
265     exit 0
266     else
267     # Well, nothing to work with...
268     echo \"No userfile. Could not reload the bot...\"
269     echo \"no userfile\" > CANTSTART.\$botname
270     exit 1
271     fi
272     fi
273     fi
274     fi
275    
276     exit 0
277     "
278 segfault 1.1 close $fd
279     puts " *** Wrote '${botnet-nick}.botchk' successfully ([file size $dir/${botnet-nick}.botchk] bytes)"
280     if {[catch {exec chmod u+x $dir/${botnet-nick}.botchk} 0]} {
281     puts " *** ERROR: unable to 'chmod u+x' the output file\n\n"
282     exit
283     }
284     puts " !! chmod u+x completed"
285     puts " *** Crontab mode?? Heaven forbid I automated this ..."
286     set tmp "[pwd]/.autobotchk"
287     if {$delay != "10"} {puts " *** Using a time delay of $delay minutes."}
288     if {$email} {
289     set line "$minutes \* \* \* \* $dir/${botnet-nick}.botchk"
290     } {
291     set line "$minutes \* \* \* \* $dir/${botnet-nick}.botchk >\/dev\/null 2>&1"
292     puts " *** Making crontab line to NOT send e-mail."
293     }
294     if {[catch {exec crontab -l > $tmp} error ]} {
295     if {![string match "*no*cron*" [string tolower $error]] &&
296     ![string match "*can't open*" [string tolower $error]]} {
297     catch {exec rm -rf $tmp} 0
298     puts " *** ERROR: unable to get crontab listing"
299     puts " *** MSG: $error\n\n"
300     exit
301     }
302     }
303     set fd [open $tmp r]
304     while {![eof $fd]} {
305     set z [split [gets $fd]]
306     if {[string match "*$dir/${botnet-nick}.botch*" $z]} {
307     puts " !! ${botnet-nick}.botchk is already crontab'd, but why?\n\n"
308     exit
309     }
310     }
311     close $fd
312     set fd [open $tmp a]
313     puts $fd $line
314     puts " !! adding new crontab line to existing crontab"
315     close $fd
316     if {[catch {exec crontab $tmp} error]} {
317     puts " *** ERROR: unable to do 'crontab $tmp'"
318     puts " *** MSG: $error\n\n"
319     exit
320     }
321     catch {exec rm -rf $tmp} 0
322 fabian 1.3 puts " !! crontab reloaded"
323     puts ""
324 segfault 1.1 puts " !! Use 'crontab -r' to remove all your crontab entries"
325 fabian 1.3 puts " !! 'crontab -l' to view the current crontabs\n\n"
326 segfault 1.1 exit
327     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23