2 command loop help
I am not sure how to create a 2 command loop script. I want it to run one command, sleep for 1 then run the other command then loop this continuously. If anyone can help me with this, thanks.
|
What part are you getting hung up on? What language?
|
I am just not sure on how to write the whole thing in Linux to create into a batch file.
|
Here's a basic tutorial on BASH scripting
http://www.tldp.org/LDP/Bash-Beginne...ers-Guide.html Beyond that, you just need to open up a text editor of your choice. |
Basically:
Code:
while true # start loop |
More bash tutorials
http://rute.2038bug.com/index.html.gz http://www.tldp.org/LDP/abs/html/ Have a crack and come back if you get stuck. We prefer to help rather than do it for you :) |
It depends on the language you want to use. For bash an example has already been given. Although calling sleep and looping is not a good practice for anything long term. Good enough for proof of concepts, but you'll burn through a lot pid's on the long haul.
|
Member Response
Hi,
Welcome to LQ! Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
Welcome to LQ.
Kooru has pretty much steered you in the correct direction, so I won't copy/paste my own variation. However a good "kudo" as well as minor warning. The kudo is good that you are thinking to have the "sleep", the warning is that if you don't have the sleep, I've found that it's sometimes difficult to exit, CTRL-C or other, a bash script. This would be on a limited distribution where things aren't always the standard. Sometimes it's minor, you merely have to attach with another command prompt and kill that other task, but if you happen to be at a point where you have no network access yet, and solely have that one console, you may find that it locks you out and you have to reboot. |
while true # start loop
do first_command # run 1st command sleep 1 # sleep for 1 second second_command # run second command done So about this code, two things. Could I put a sleep after the second command or is that unnecessary? Also is everything after the # not apart of the code and it can be deleted? |
Quote:
# in BASH denotes a comment, everything after it is ignored by the interpreter (unless it's on the first line and is part of a shebang, but that's another topic). |
Quote:
|
Another thing to do is the absolute first line of the script should contain this, for bash
Code:
#!/bin/bash Code:
#!/bin/sh I'd recommend you peruse this link if you have more specific questions about the first line Starting Off With a She-Bang if you go down about a page, it explains the purpose more better than I could, or should: Quote:
|
All times are GMT -5. The time now is 02:28 PM. |