#!/usr/bin/expect
#
# This is a wretched expect script to startup HOD and scrap the necessary
# information we need to run Pig. Tragically, we can't just pipe HOD's output
# into a script, so we have to use expect. Also the real information we need
# is not given to us on stdout; rather, we get the name of the configuration
# file with the information we need on stdout. We have to write actual TCL to
# parse the file.
#
#
# Quick and dirty parser to extract the value of mapred.job.tracker
#
trap handleExit {SIGINT SIGTERM SIGHUP SIGABRT SIGPIPE}
proc handleExit {} {
send "exit\n"
set timeout 20
expect "do not CTL-C"
puts "Exiting"
exit
}
proc extractMapRedHostPort {file} {
set fh [open $file r]
set line [read $fh]
close $fh
regexp {>mapred.job.tracker[^<]*([^<]*)} $line match sub
return $sub
}
#
# Quick and dirty parser to extract the value of fs.default.name
#
proc extractDFSHostPort {file} {
set fh [open $file r]
set line [read $fh]
close $fh
regexp {>fs.default.name[^<]*([^<]*)} $line match sub
return $sub
}
set mOpt {"-m" "15"}
foreach i $argv {
if {$i == "-m"} {
set mOpt {};
}
}
log_user 0
set timeout -1
#spawn /export/crawlspace/kryptonite/hod/current/bin/hod -n [join [concat $argv $mOpt]]
#set args [split [join [concat $argv $mOpt]]]
set args [concat $argv $mOpt]
spawn -ignore {SIGHUP} /export/crawlspace/kryptonite/hod/current/bin/hod -n [lindex $args 0 ] [lindex $args 1] [lindex $args 2] [lindex $args 3] [lindex $args 4] [lindex $args 5] [lindex $args 6 ] [lindex $args 7] [lindex $args 8] [lindex $args 9] [lindex $args 10]
expect "HDFS UI on "
expect "\n"
puts -nonewline "hdfsUI: $expect_out(buffer)"
expect "Mapred UI on "
expect "\n"
puts -nonewline "mapredUI: $expect_out(buffer)"
expect "Hadoop config file in: "
expect "\n"
puts -nonewline "hadoopConf: $expect_out(buffer)"
puts "hdfs: [extractDFSHostPort [string trim $expect_out(buffer)]]\r"
puts "mapred: [extractMapRedHostPort [string trim $expect_out(buffer)]]\r"
#
# Now just wait forever. Eventually we will be ruthlessly killed.
#
expect_user {
eof { handleExit }
timeout {exp_continue}
}