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

Annotation of /eggdrop1.4/scripts/autobotchk

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


Revision 1.5 - (hide annotations) (download)
Wed Dec 15 02:32:57 1999 UTC (19 years, 10 months ago) by guppy
Branch: MAIN
CVS Tags: eggdrop104030RC2, eggdrop10403RC1, eggdrop10402RC1, eggdrop10404, eggdrop10403, eggdrop10402, HEAD
Changes since 1.4: +2 -0 lines
id-header patch, finally, we have id tags for each file

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23