LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Input from file to screen (https://www.linuxquestions.org/questions/linux-server-73/input-from-file-to-screen-517663/)

TB_205gti 01-09-2007 07:12 AM

Input from file to screen
 
Hi, I use screen to connect to /dev/ttyS0 to do some tasks via the COM port, but I need a script to do this. As it is now I have to manualle start screen and enter the commands I need to use, but how can I the contants of a text file to do this? I really need this in order to use some analysis scripts.

If it is not possible with screen, is it then possible with another tool? (bash, perl, python are welcome..)

wjevans_7d1@yahoo.co 01-09-2007 08:23 AM

I'm not sure exactly what you're trying to say, but try this command at the shell prompt:

man expect

Hope this helps.

TB_205gti 01-09-2007 09:44 AM

Quote:

Originally Posted by wjevans_7d1@yahoo.co
I'm not sure exactly what you're trying to say, but try this command at the shell prompt:

man expect

Hope this helps.


This is what I have been looking for :)

Next problem.. This is my simple expect input file..

spawn screen /dev/ttyS0
send "ATE"
expect "OK"
send "at+cmgf=1"
expect "OK"
exp_eof

Problem is that screen is started, but something goes wrong. The ATE command is sent just fine, but i never gets an "OK" and thus times out.

this is the output of expect -d [file]

expect: does "ATE\u001b[?1049h\u001b[r\u001b[m\u001b[2J\u001b[H\u001b[?7h\u001b[?1;4;6l\u001b[4l\u001b[?1h\u001b=\u001b[0m\u001b(B\u001b[1;39r\u001b[H\u001b[2J\u001b]2;[screen -] \u0007\u001b[H\u001b[2J\u001b]2;screen\u0007\u001b]2;[screen 0: ttyS0] \u0007" (spawn_id exp4) match glob pattern "OK"? no
expect: timed out
send: sending "at+cmgf=1" to { exp4 }

expect: does "ATE\u001b[?1049h\u001b[r\u001b[m\u001b[2J\u001b[H\u001b[?7h\u001b[?1;4;6l\u001b[4l\u001b[?1h\u001b=\u001b[0m\u001b(B\u001b[1;39r\u001b[H\u001b[2J\u001b]2;[screen -] \u0007\u001b[H\u001b[2J\u001b]2;screen\u0007\u001b]2;[screen 0: ttyS0] \u0007" (spawn_id exp4) match glob pattern "OK"? no
expect: timed out
invalid command name "exp_eof"
while executing
"exp_eof"
(file "in" line 6)

(I know about the eof error..)


If I enter the commands manually screenlog.0 gives this:

[bubba@jupiter ~]# cat screenlog.0

OK

OK

OK
[bubba@jupiter ~]#

But if I use expect, screenlog.0 is empty :(

wjevans_7d1@yahoo.co 01-10-2007 06:06 AM

screen sends all sorts of cursor-related stuff to its output (in other words, to your screen and to expect). This complicates things if you're looking for a simple "OK". Try to find some other way to do this without using screen.

TB_205gti 01-10-2007 08:42 AM

wjevans_7d1@yahoo.co: I use screen to connect to a nokia phone through a DLR3 cable. I'm used to screen, but if there are other applications with wich I can connect to the phone and send AT commands, they may be a better choice.

wjevans_7d1@yahoo.co 01-11-2007 07:02 AM

I've just reread your original post. If your goal is to use analysis scripts, I'm hoping that you mean it's ok to do the analysis after the whole session is done, rather than in real time while the session is in progress.

If that is the case, don't use screen and don't use expect. Use minicom, and turn logging on. After the session is over, you'll have a clean file that just shows the traffic back and forth. You can use your analysis scripts on that.

Hope this helps.

TB_205gti 01-11-2007 12:22 PM

Quote:

Originally Posted by wjevans_7d1@yahoo.co
I've just reread your original post. If your goal is to use analysis scripts, I'm hoping that you mean it's ok to do the analysis after the whole session is done, rather than in real time while the session is in progress.

If that is the case, don't use screen and don't use expect. Use minicom, and turn logging on. After the session is over, you'll have a clean file that just shows the traffic back and forth. You can use your analysis scripts on that.

Hope this helps.

Maybe my post isn't that clear ;) English is not my mothers tonque :)

I have some scripts that log system specific "things" - I need to send a status sms via the Nokia phone I have atteched to the server.
Normally I use screen /dev/ttyS0 and the enter the AT commands in order to send a sms.
Now I want a script to be able to do that - sending a status sms automatically.
The reason I would use screen is that I can use that to send AT commands to the phone.

wjevans_7d1@yahoo.co 01-12-2007 06:10 AM

Instead of using screen, you can use minicom to send AT commands to the phone.


All times are GMT -5. The time now is 06:53 PM.