LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2008, 07:21 AM   #1
stlouis
Member
 
Registered: Jul 2006
Location: Sault Ste. Marie, Ontario
Distribution: RedHat, CentOS, Fedora Core, Gentoo, Slackware
Posts: 63

Rep: Reputation: 16
Scripting Question


Hi,


I was just wondering if something was possible in BASH, and if so, how to go about it.

I have a Character Based software based on the old CADOL Systems, and am trying to automate functions, by recording keystrokes with "TEE" then replaying, similar to how you would automate an FTP Script. I can get this to work fine, however, it runs extremely fast, and the user really can't see what's going one, so I would like to slow down the process by issuing a sleep 1 command or somethings between each command, but I have no idea how to go about this.

eg.

ftp my.host.com << EOF
command
command
command
command
EOF

myprogram << EOF
command
command
command
command
EOF

Is is possible to have the script sleep for 1 second between each command? Can this be done with BASH? Am I approaching this the wrong way? Should I maybe try a while/until loop? Just looking for some pointers here, to see if I'm chasing something that can't be done.

I think I could use gnu expect, but my software displays more than just one line responses like FTP, so this would be huge, at least I think.


Thanks,

Jeff
 
Old 01-24-2008, 08:06 AM   #2
stlouis
Member
 
Registered: Jul 2006
Location: Sault Ste. Marie, Ontario
Distribution: RedHat, CentOS, Fedora Core, Gentoo, Slackware
Posts: 63

Original Poster
Rep: Reputation: 16
I think I answered my own question. I was just approaching this issue wrong... I just stumbled upon the "script" and "scriptreplay" commands, for recording and replaying Terminal Sessions.

I am going to give this a go... It would be nice to know if what I wanted to do can be done with BASH though, via an alternate method... And besides, there is more than one way to skin a cat, you just got to find the most efficient...

TIA
 
Old 01-24-2008, 08:29 AM   #3
stlouis
Member
 
Registered: Jul 2006
Location: Sault Ste. Marie, Ontario
Distribution: RedHat, CentOS, Fedora Core, Gentoo, Slackware
Posts: 63

Original Poster
Rep: Reputation: 16
Guys,


The script command isn't what I was looking for... It is a nice little utility, it's NOT quite what I was looking for.

So I must revert back to using TEE and trying to figure out some way to controll the timing of the commands being issued, as mentioned above...

Any help or pointers is very much appreciated... TIA
 
Old 01-24-2008, 08:38 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you use "mget" in your ftp script without the "-i" option, the user will be prompted whether to download each file in the "mget" command. The slowdown you want is when the ftp command is running the HERE document script and not when the shell is running commands.
 
Old 01-24-2008, 09:00 AM   #5
stlouis
Member
 
Registered: Jul 2006
Location: Sault Ste. Marie, Ontario
Distribution: RedHat, CentOS, Fedora Core, Gentoo, Slackware
Posts: 63

Original Poster
Rep: Reputation: 16
I apologize... But I'm NOT sure what your are trying to tell me here...

I actually understand the -i option for interactive ftp, and how to turn it on and off... The script I'm trying to write, has nothing to do with FTP, I just posted an FTP Example, as what I'm trying to do is similar...

I'm able to record the keystrokes with "tee", which is great... I'm able to replay the keystrokes like:

myprogram << EOF
cmd1
cmd2
cmd3
exit
EOF

This works perfectly, but it just goes way too fast... You can't tell if an error appeared or NOT..

I want to do something like:

myprogram << EOF
cmd1
sleep or wait 1 or 2 Secs
cmd2
sleep or wait 1 or 2 Secs
exit
EOF

Unfortunately, my program does respond to sleep, pause, wait, etc.... commands, and I need to find another way to slow this down, so the user can actually watch the session replay, step by step, ensuring every goes OK...

I was hoping I could do this with some type of loop or something...

while myprogram !=0
do
command && sleep 1
command && sleep 1
until
EOF


Jeff
 
Old 01-24-2008, 03:26 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Your first example was using ftp and the program in the here document would be a list of ftp commands.

In your second example, the command is run and standard input is taken from the here document. The here document doesn't contain commands to be run. Perhaps you could provide more info on what your command is.
 
Old 01-24-2008, 03:35 PM   #7
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Rep: Reputation: 31
This sounds like a textbook usage for expect, if you ask me. If you could post some example output from your program and what the automated version should do, someone should be able to give a little more help. But expect has nothing to do with one line vs. many lines, just a matter of being sure that your program gives "expect"able output, i.e. something that can easily be handled with a "if you see this, then do this" structure.
 
Old 01-24-2008, 05:01 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I think we need a real example of your prog & how it works, so we can analyse it properly.
If groups of 'cmds' as being handled internally by your 'prog', then you have to change the code in your prog to sleep in between each thing it does.
If you are calling your prog separately for each 'cmd', then you can insert a sleep(1) in between each invocation.
 
  


Reply



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
Scripting question msandford Linux - Newbie 4 09-05-2005 10:23 AM
Scripting question buster_balz Linux - General 8 05-18-2005 03:30 PM
Scripting Question Darklight451 Linux - Newbie 4 11-12-2004 11:14 AM
Scripting Question... Darklight451 Linux - Newbie 3 09-23-2004 05:03 PM
scripting question cyph3r7 Linux - General 1 04-05-2004 02:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 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
Open Source Consulting | Domain Registration