• 5

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

the following expect script target is to print the hostname name from linux/solaris machine and according to hostname results expect script will run linux.ksh or solaris.ksh script

expect_sun_script=`cat << EOF
set timeout -1
spawn   telnet 0 $IP_ADDRESS

expect login:           {send $LOGIN\r}
expect Password:        {send "PASS\r"}

expect -re {#|>}        {send "/bin/hostname\r"}

so - after I get the hostname name I need to run linux.ksh for hostname - machine1

or if I get hostname - machine2 then I need to run the script - solaris.ksh

but how expect can run the script according to the hostname name?

according to my example below:

expect actually wait for machine1 - but it could be machine2 so its stuck ....

my target is to run linux.ksh or solaris.ksh according to the relevant hostname

please advice ?

expect "machine1"            { send "/var/tmp/linux.ksh\r "  } 
expect "machine2"            { send "/var/tmp/solaris.ksh\r" }


I think you can do something like

expect "machine1" {send "/var/tmp/linux.ksh\r" } \
"machine2"  { send /var/tmp/solaris.ksh\r" } \

Having said that it may be easier to use uname which will return Linux and SunOS respectively and should make the management of the script much easier as hosts come and go.

expect -re {#|>}        {send "PATH=/bin:/usr/bin:$PATH uname\r"}

expect "Linux" { send /var/tmp/linux.ksh\r" } \ 
expect SunOS { send /var/tmp/solaris.ksh\r" }

Note that the uname command is in /bin for Linux and /usr/bin for Solaris so we set the PATH before the command to ensure that it is correctly found on either system.

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags