I want to run a command for ever in the Linux bash. Also I want to put 60 seconds between command execution.

asadalikhan commented: while true; do your-command; sleep 60; done +0

Recommended Answers

All 7 Replies

For me that's a script with three lines.
Echo something.
do something
sleep 60
goto top

This is psuedo code so you need to craft it for the shell you use.

You can use bash infinite loops with the while loop like

while true; do echo "test"; sleep 60; done

Be Careful what you wish for. When I was first using Unix one of our programmers wrote a Bash script something like:
While 1
Do Something

He eventually overloaded the system and it crashed.

while true; do echo "Running..."; sleep 60; done
This runs forever, printing "Running..." every 60 seconds. No script file needed, just drop it in the terminal and you're good.

Create an infinite loop in Bash to run commands continuously without stopping. It is useful for monitoring systems, automation tasks, and repeating scripts until manually interrupted using Ctrl + C.

You can do this with a simple Bash loop:

while true; do
    your_command_here
    sleep 60
done

This will run your_command_here, wait 60 seconds, and then repeat indefinitely. If you want it to keep running after you log out, consider using nohup, screen, or tmux.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.