ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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...
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.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.