#!/usr/bin/expect -f

set timeout 3
set user [lindex $argv 0]
set passwd [lindex $argv 1]

spawn mysql -u $user -p
expect {
"password*" { send "$passwd\n"}
}
expect {
"ERROR*"    { puts "Wrong User or Wrong Passwd. Use root to login please.";  exit -1 }
}
expect "mysql*"
send "show databases;\n"
expect {
"icinga*mysql*" { send "drop database icinga;\n" }
}
expect "Query OK*"
expect "mysql*"
send "create database icinga;\n"
expect "Query OK*"
expect "mysql*"
send "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON icinga.* TO icinga@localhost IDENTIFIED BY 'icinga';\n"
expect "Query OK*"
expect "mysql*"
send "quit\n"

