/[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.4 - (hide annotations) (download)
Sun Oct 24 09:19:00 1999 UTC (19 years, 11 months ago) by guppy
Branch: MAIN
Changes since 1.3: +109 -55 lines
autobotchk update

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23