Main Menu

Search

LINUX: While Loop Command To Run Command(s) Continuously (How To Doc) ("while" loop Command)

Below is the command to use.


# while true; do date;hostname ; sleep 1; done

In above command example we are running and date, hostname commands followed by 1 second sleep. All these 3 commands keep running in a loop until Ctrl C is done to exit out. You can replace commands in above command with the commands you want to run continuosly in while loop.

Below is example output of above command.


Thu Sep 19 14:31:39 EDT 2019
linux-test-machine
Thu Sep 19 14:31:40 EDT 2019
linux-test-machine
Thu Sep 19 14:31:41 EDT 2019
linux-test-machine
Thu Sep 19 14:31:42 EDT 2019
linux-test-machine
Thu Sep 19 14:31:43 EDT 2019Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0b:12:45:53:31:78:64:7d:68:b9:1c:54:36:2d:51:3e root@source-vm
The key's randomart image is:
+--[ RSA 2048]----+
|     .++*+.+=+.  |
|     ..o..*.oo.  |
|    .  . o + .E  |
|     .    o    . |
|    . . S        |
|     . . .       |
|        .        |
|                 |
|                 |
+-----------------+

Products to which Article Applies

All Linux Operating Systems. The steps in this article should also work on other UNIX bases Operating systems. 

Additional References

https://www.tecmint.com/run-repeat-linux-command-every-x-seconds/



tarun boyella







No comments:

Post a Comment