Expect scripting issue, works interactively when doing commands in cli, does not work in script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Expect scripting issue, works interactively when doing commands in cli, does not work in script
# 1  
Expect scripting issue, works interactively when doing commands in cli, does not work in script

Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue.

I am doing some word extracting from multiline text.

Interacting in CLI seems to work without issues. First step is to add multiline text to a variable.

Code:
expect1.1>
expect1.1> set multilinetext "first one two\nsecond one two three\nthird one\nfourth one two three four\nfifth one two"
first one two
second one two three
third one
fourth one two three four
fifth one two
expect1.2>

But I tried that inside script, no result, always getting error messages. Here are 5 attempts.

Code:
#!/bin/bash

expect -c "

set multilinetext \"first one two\\nsecond one two three\\nthird one\\nfourth one two three four\\nfifth one two\";
#     multilinetext=\"first one two\nsecond one two three\nthird one\nfourth one two three four\nfifth one two\";
#     set multilinetext 'first one two\nsecond one two three\nthird one\nfourth one two three four\nfifth one two';
#     set multilinetext \"first one two\nsecond one two three\nthird one\nfourth one two three four\nfifth one two\";
#     set multilinetext "first one two\nsecond one two three\nthird one\nfourth one two three four\nfifth one two"

;"

Errors are from the:
Code:
wrong # args: should be "set varName ?newValue?"
    while executing

To the:
Code:
couldn't read file "one": no such file or directory

And this is just the first step. Have to ask if somebody has correct command and explanation.

Thank you.
# 2  
Have you tried:
Code:
#!/bin/bash

expect -c "

set multilinetext 'first one two
second one two three
third one
fourth one two three four
fifth one two'

;"

?
# 3  
Hi;
Thanks for replying, sorry for my delayed response.

Code:
cat test.sh
#!/bin/bash

expect -c "

set multilinetext 'first one two
second one two three
third one
fourth one two three four
fifth one two'

;"

Error:
 ./test.sh
wrong # args: should be "set varName ?newValue?"
    while executing
"set multilinetext 'first one two"


It looks that the "-c" commands calling parameter in bash, can create number of different errors.

I am now trying to separate all Expect from Bash - Expect dedicated files called from main bash files.

It seems to have lots of benefits, also some drawbacks.

Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags for clarity.
It also preserves spaces for indenting or fixed-width data.

Last edited by rbatte1; 09-04-2019 at 02:46 PM..
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #495
Difficulty: Easy
Blocks of code cannot be nested within each other to form sub-blocks.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script works on CLI, but not under Nagios

I'm having a problem scripting Expect to work as a Nagios check. The script runs fine from the cli, but not when run as a Nagios check. I turn on the debug output, and it looks like it's not seeing the whole buffer's worth of info, like it's paged interactively somehow. I'm new to Expect, but this... (1 Reply)
Discussion started by: dhargens
1 Replies

2. UNIX for Dummies Questions & Answers

C-program works fine interactively, but not on the SGE server

Greetings, I have a C-program that is made to implement a hidden Markov model on an input file. The program is very memory intensive. I've installed it on my local server where I have an account and it compiles fine. The way they have the server set up is that you can either work... (1 Reply)
Discussion started by: Twinklefingers
1 Replies

3. Shell Programming and Scripting

Not the correct output, works fine via CLI, not inside the script.

Guys, I need you help please. The script below is not working correclty for checking via a awk/if statement . Can you tell me what i am doing wrong in the script code "if($1 == "$RETENTION_LEVEL") " Syntax RETENTION_LEVEL=`echo $LINE | cut -f2 -d" "` echo " ==============... (4 Replies)
Discussion started by: Junes
4 Replies

4. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

5. Shell Programming and Scripting

simple php/expect script works from command line but not from web

I have a really basic expect script which I call from php. I works fine when I run the php from the shell, but from the web it appears as if the output buffer gets chopped and never gets all of the contents. php script: (runexpect.php) <?php... (7 Replies)
Discussion started by: jacksona2
7 Replies

6. Shell Programming and Scripting

Issue with script in linux but in unix works

I have this simple script: #! /usr/bin/sh #***************************************************************************** # *** get_input (question variable) *** #***************************************************************************** get_input () { echo "${BOLD}${1} : " read... (14 Replies)
Discussion started by: C|KiLLeR|S
14 Replies

7. Shell Programming and Scripting

Expect script doesn't work under crontab

Hi All, Using Expect script when I run it manually it works. But when I put the entry in crontab, the job is still running after 15 hours. The script was created as root. I don't think it's a permission issue. Any idea? This is what I have under root crontab... 00 18 * * 1-5... (4 Replies)
Discussion started by: samnyc
4 Replies

8. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

9. Shell Programming and Scripting

Script that works on one server does not work on another

Hello all, The following script (sess.sh) runs fine and gives the correct output on a SunOS 5.9 ( default shell =/bin/ksh) but gives incorrect results on a SunOS 5.7 (default shell= /bin/sh). The script logs on to an oracle database and queries the total no of sessions running in the database... (6 Replies)
Discussion started by: luft
6 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

Featured Tech Videos