LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-12-2012, 02:54 PM   #1
jefsa
Member
 
Registered: Mar 2012
Posts: 56

Rep: Reputation: Disabled
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
 
Old 04-12-2012, 03:38 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by jefsa View Post
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

Last edited by Tinkster; 04-12-2012 at 03:39 PM.
 
Old 04-13-2012, 07:55 AM   #3
jefsa
Member
 
Registered: Mar 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-13-2012, 05:22 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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?
 
Old 04-20-2012, 10:43 AM   #5
jefsa
Member
 
Registered: Mar 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect/TCL Logging -- any way to create a clean log file? keller999 Programming 1 04-18-2011 12:27 PM
[SOLVED] read a text file distrubute its contents on different text files magische_vogel Programming 13 02-26-2011 06:51 PM
tcl/expect stdout redirected to file stops (possibly due to a "@" in exp_send) cejennings_cr Programming 1 07-08-2009 06:01 PM
cutting down contents of text file kam_kenneth Linux - Newbie 2 05-22-2004 01:16 AM
tar from contents of a text file trpn Linux - General 3 03-08-2004 01:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration