LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using Expect/TCL to move contents of a text file to an executable file (https://www.linuxquestions.org/questions/linux-newbie-8/using-expect-tcl-to-move-contents-of-a-text-file-to-an-executable-file-939515/)

jefsa 04-12-2012 02:54 PM

Using Expect/TCL to move contents of a text file to an executable file
 
Hi All,

Could use a little help here. After running a expect script I have some lines of data that are put into a non-executable text file.

From this file I want to be able to extract this data into a executable file where I can use the "if" command to make a conditional expression(s) on this data. Since the length of each data line is long, I figure I can set a "variable" for each one, making it more pratical using them in a "if" statement(s).

I do not understand how to do this from the text file to the executable file that I want to create.

I have looked at a TCL manual but understanding the info in it is not clear.

Thanks.

Regards,

Jeff

Tinkster 04-12-2012 03:38 PM

Quote:

Originally Posted by jefsa (Post 4651279)
Hi All,

Could use a little help here. After running a expect script I have some lines of data that are put into a non-executable text file.

From this file I want to be able to extract this data into a executable file where I can use the "if" command to make a conditional expression(s) on this data. Since the length of each data line is long, I figure I can set a "variable" for each one, making it more pratical using them in a "if" statement(s).

I do not understand how to do this from the text file to the executable file that I want to create.

I have looked at a TCL manual but understanding the info in it is not clear.

Thanks.

Regards,

Jeff


Can you try to rephrase the request? I can't understand at all what you're saying.

Ideally provide some sample input, and the desired result.


Cheers,
Tink

jefsa 04-13-2012 07:55 AM

Hi Tink,

I will try;

I have a expect script that logs in and then controls a Cisco switch. At a point in the script I have the script write the following results into a non-executable file called "display". This file is setup so that each
time the script is ran it will append the results to it. The following is a sample of what is in this file:

(p1)RICI_C RB RICI_A(p7)
(p13)RICI_D RB RICI_A(p7)
(p19)RICI_E RB RICI_B(p7)

What I want to do next is run an executable file with these results. Since each of these results are long I believe I want to make eash one a "variable" to make it easier to work with. I then want to put these into the executable file and run "if" statements on them and output the results to my terminal.

So what I have here is two files; one non-executable that holds the data and the second one an executable that will compare using "if" statements. What I am having problems with is how to work between the two files; making a variable for each result then transferring them into the executable one.

The TCL manual that I am using is not clear to me on how to do this.

Thanks.

Regards,

Jeff

Tinkster 04-13-2012 05:22 PM

I still don't understand what the resulting executable is supposed to
look like. How do the lines above look when combined with the if-
statements?

jefsa 04-20-2012 10:43 AM

Hi Tink,

Was able to solve my issue. What I did was in my original expect script I used the "set", "puts", and "close"
commands to create variables. These variables contained text srings that were put under files. Each time the script was ran for a particular "switch" event the associated file would update not append. These files are the
non-executable files.

I then wrote script files (executables), this time under bash, based on these files. Once again variables were used and linked to the data that were in each file. I then used the "if" statement as shown below for one switch condition. This is an example of one of the "if" statements:

shortrange2=`cat /home/jeff/RICI_Switch/display_p19`
longrange2=`cat /home/jeff/RICI_Switch/display_p19`
if [ "shortrange2" = "(p19)RICI_E RB RICI_A(p7)" ] ; then
echo "(p19)RICI_E RB RICI_A(p7)"
elif [ "$longrange2" = "(p19)RICI_E RB RICI_B(p24)" ] ; then
echo "(p19)RICI_E RB RICI_B(p24)"
else
echo "Offline"

It is simple but it took sometime to achieve this step and it works!!

Thanks.

Regards,

Jeff


All times are GMT -5. The time now is 10:33 AM.