Can i use if else inside expect command in shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can i use if else inside expect command in shell script?
# 1  
Old 07-27-2012
Can i use if else inside expect command in shell script?

hii,,
I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this:
Code:
"Configure which ports JIRA will use.
JIRA requires two TCP ports that are not being used by any other
applications on this machine. The HTTP port is where you will access JIRA
through your browser. The Control port is used to Startup and Shutdown JIRA.
Use default ports (HTTP: 8080, Control: 8005) - Recommended [1, Enter], Set custom value for HTTP and Control ports [2]"

here i want to change the port if i have entered a string for that port or just continue with the default.if i am trying with the custom values, i will get the message like that, i want to type enter the custome values there.

all these process iam doing with expect and i getting done when i go without changing the port values.my succeess code is as below:
Code:
/usr/bin/expect <<EOD

spawn sudo ./atlassian-jira-5.1-x64.bin

expect "This will install JIRA 5.1 on your computer."
send "\r" 
expect "Choose the appropriate installation or upgrade option."
send "\r" 
expect "Where should JIRA 5.1 be installed?"
send "\r" 
expect "Choose the appropriate installation or upgrade option."
send "\r" 
expect "Default location for JIRA data"
send "\r" 
expect "Configure which ports JIRA will use."
send "\r" 
expect "JIRA can be run in the background."
send "\r" 

EOD

but now when i tried to change that ports , my code is:
Code:
/usr/bin/expect <<EOD
spawn sudo ./atlassian-jira-5.1-x64.bin
expect "This will install JIRA 5.1 on your computer."
send "\r" 
expect "Choose the appropriate installation or upgrade option."
send "\r" 
expect "Where should JIRA 5.1 be installed?"
  if [ -z "$location" ]; then 
    send "\r"
  else
    send "$location\r" 
  fi 
expect "Choose the appropriate installation or upgrade option."
send "\r" 
expect "Default location for JIRA data"
  if [ -z "$default_locaton" ]; then
    send "\r"
  else
    send "$default_locaton\r" 
  fi 
expect "Configure which ports JIRA will use."
  if [ -z "$config_port" -a -z "$control_port" ]; then
    send "\r" 
  elif [ -n "$config_port" -a -z "$control_port" ]; then
    send "2\r"
    expect "HTTP Port Number"
    send "$config_port\r"    
    expect "Control Port Number"
    send "\r"
  elif [ -z "$config_port" -a -n "$control_port" ]; then
    send "2\r"
    expect "HTTP Port Number"
    send "\r"    
    expect "Control Port Number"
    send "$control_port\r"
  elif [ -n "$config_port" -a -n "$control_port" ]; then
    send "2\r"
    expect "HTTP Port Number"
    send "$config_port\r"    
    expect "Control Port Number"
    send "$control_port\r"
  fi 
expect "JIRA can be run in the background."
send "\r" 

EOD

and iam getting the error as:
Code:
invalid command name "-z"
    while executing
"-z "/opt/atlassian/jira/jiranew" "
    invoked from within
"if [ -z "/opt/atlassian/jira/jiranew" ]"

Please give mea solution ASAP.
thanks...Smilie

Last edited by Scott; 07-27-2012 at 06:54 AM.. Reason: Please use code tags
# 2  
Old 07-27-2012
That's just not how if statements work in expect, if I'm reading it right. Most of your checks come down around like the below:

I don't have expect handy this second, but I think this would be right
Code:
if {0 == [llength $config_port]} {
            send "Something\r"
}

You just need to adjust how you're doing if statements - bourne syntax isn't right for an expect/tcl script.
This User Gave Thanks to Vryali For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to merge Expect script inside shell script?

Hi I have two scripts one is Expect and other is shell. I want to merge Expect code in to Shell script so that i can run it using only one script. Can somebody help me out ? Order to execute: Run Expect_install.sh first and then when installation completes run runTests.sh shell script. ... (1 Reply)
Discussion started by: ashish_neekhra
1 Replies

2. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

3. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

4. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

5. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

6. Shell Programming and Scripting

How to monitor a command inside shell script

Hi All, Is there any way to monitor a command inside shell script ? I have a script inside which I have a tar command which zips around 200GB data. tar zcvf $Bckp_Dir/$Box-BaseBackup-$Day.tar.gz * --exclude 'dbserver_logs/*' --exclude postmaster.pid --exclude 'pg_xlog/*' I want to... (3 Replies)
Discussion started by: sussus2326
3 Replies

7. Shell Programming and Scripting

Error while using sqlplus command inside 'if' condition in an unix shell script

Hi all, I am using the below given sqlplus command in my unix script to invoke a stored procedure which returns a value .It works fine. RET_CODE=$(/opt/oracle/product/10.2.0.4.CL/bin/sqlplus -S $USER/$PASSWD@$DB_NAME <<EOF EXEC MY_PKG.MY_SP (:COUNT); PRINT COUNT; commit; ... (6 Replies)
Discussion started by: Shri123
6 Replies

8. Shell Programming and Scripting

how to run shell script inside expect script?

I have the code like this : shell script continues ... .... expect -c" spawn telnet $ip expect "login:" send \"$usrname\r\" expect "Password:" send \"$passwd\r\" expect "*\>" send \"$cmdstr\r\" ... (1 Reply)
Discussion started by: robbiezr
1 Replies

9. Shell Programming and Scripting

how to redirect the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (11 Replies)
Discussion started by: kripssmart
11 Replies

10. UNIX for Dummies Questions & Answers

how to get the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (1 Reply)
Discussion started by: kripssmart
1 Replies
Login or Register to Ask a Question