This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Result of my script into channel topic?

Old posts that have not been replied to for several years.
Locked
D
DigitalXXL

Result of my script into channel topic?

Post by DigitalXXL »

Hi Guys!

I made a small script wich checks if a FTP Server is up or down and shows the result of the test in an irc channel. Works fine so far. Now to my question. Is it possible, that the result of the script is put into the channel topic? It should look something like this
"FTP 1 up | FTP 2 up | FTP 3 down | FTP 4 up".
Is that possible somehow?

Code: Select all

 
package require ftp

bind pub - .ftp ftp


proc ftp { nick uhost hand chan arg } {
ftp1 $nick $uhost $hand $chan $arg 
ftp2 $nick $uhost $hand $chan $arg 
ftp3 $nick $uhost $hand $chan $arg 
ftp4 $nick $uhost $hand $chan $arg
}


proc ftp1 { nick uhost hand chan arg } {

set biglist1 {xxx.xxx.xxx.xxx log pas}
foreach {addr uid pwd} $biglist1 {
 set statval [ftp::Open $addr $uid $pwd -port 444]
 if {$statval<0} {
    putserv "PRIVMSG $chan : \002FTP 1\002 \0034down\0034!"
 } else {
    putserv "PRIVMSG $chan : \002FTP 1\002 \0039up\0039!"
    ftp::Close $statval;
  }
 }
}

proc ftp2 { nick uhost hand chan arg } {

set biglist2 {xxx.xxx.xxx.xxx log pas}
foreach {addr uid pwd} $biglist2 {
 set statval [ftp::Open $addr $uid $pwd -port 444]
 if {$statval<0} {
    putserv "PRIVMSG $chan : \002FTP 2\002 \0034down\0034!"
 } else {
    putserv "PRIVMSG $chan : \002FTP 2\002 \0039up\0039!"
    ftp::Close $statval;
  }
 }
}

proc ftp3 { nick uhost hand chan arg } {

set biglist3 {xxx.xxx.xxx.xxx log pas}
foreach {addr uid pwd} $biglist3 {
 set statval [ftp::Open $addr $uid $pwd -port 444]
 if {$statval<0} {
    putserv "PRIVMSG $chan : \002FTP 3\002 \0034down\0034!"
 } else {
    putserv "PRIVMSG $chan : \002FTP 3\002   \0039up\0039!"
    ftp::Close $statval;
  }
 }
}

proc ftp4 { nick uhost hand chan arg } {

set biglist4 {xxx.xxx.xxx.xxx log pas}
foreach {addr uid pwd} $biglist4 {
 set statval [ftp::Open $addr $uid $pwd -port 444]
 if {$statval<0} {
    putserv "PRIVMSG $chan : \002FTP 4\002 \0034:(\0034"
 } else {
    putserv "PRIVMSG $chan : \002FTP 4\002   \0039:)\0039"
    ftp::Close $statval;
  }
 }
}

putlog "Loaded ftp_test.tcl by DigitalXXL"
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Result of my script into channel topic?

Post by user »

Why have one proc for each ftp?

Code: Select all

package require ftp
bind pub - .ftp ftps

proc ftps {nick uhost hand chan arg} {
	set out {}
	# just add your ftps to this list (make sure you don't
	# leave any fields blank or mess up the order :P)
	set list {
		{"FTP 1" ftp.addr1.cum 444 login pass}
		{"FTP 2" ftp.addr2.cum 21 login pass}
		{"FTP 3" ftp.addr3.cum 3131 login pass}
		{"FTP 4" ftp.addr4.cum 9999 login pass}
	}
	foreach ftp $list {
		foreach {name addr port user pass} $ftp break
		set ftp [ftp::Open $addr $user $pass -port $port]
		if {$ftp<0} {
			lappend out "$name is down"
		} {
			lappend out "$name is up"
		}
		ftp::Close $ftp
	}
	putserv "TOPIC $chan :[join $out " | "]"
}
Have you ever read "The Manual"?
D
DigitalXXL

Post by DigitalXXL »

Thanks for your quick help! Works great! Now one last thing... I want that the scripts runs every 2 hours. Is that possible somehow?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Code: Select all

# this bind will call the proc below once every hour
bind time - 00* ftps:timed
proc ftps:timed args {
	# this calculation makes sure it's only run at hours 00, 02, 04 etc
	if {![expr {[format %g [lindex $args 1]]%2}]} {
		# remember to change the channel name below :)
		ftps {} {} {} #channel {}
	}
}
Have you ever read "The Manual"?
Locked