How to execute shell commands in a loop from within a bash script?

Roshan singh

I want to write a script which will run on my android phone & perform the following things:

echo "1" > /sys/kernel/mm/ksm/run

wait for 2 minutes: then

echo "0" > /sys/kernel/mm/ksm/run

then wait for 2-3hrs & loop over again.

Pandya

You can use sleep with while loop as follows:

while true;
do
echo "1" > /sys/kernel/mm/ksm/run;
sleep 120;
echo "0" > /sys/kernel/mm/ksm/run;
sleep 7200;
done;

Here, while Loop starts with condition while true; that means no condition for stopping loop (it runs forever until script is killed) then commands will be run (with sleeping as you wish) at done; loop will be redirected to condition that is while true; thus, It will again start executing commands.

Note: with GNU sleep you can also use sleep 2m, sleep 2h etc.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to execute git commands from bash script?

From Dev

Shell out into zsh and execute commands from bash script

From Dev

How to execute commands in docker container as part of bash shell script

From Dev

How to execute an input asking utility in a loop within a shell script?

From Dev

Cannot execute shell commands in bash script

From Dev

How to execute a shell script from within an .app, and show it in the Terminal?

From Dev

how to execute a script within a script in shell command

From Dev

Can a bash shell script open a text file with less and then execute less commands from the script?

From Dev

How to execute the vim commands through shell script

From Dev

How to execute commands in gnuplot using shell script?

From Dev

how to execute compound commands in shell script?

From Dev

Bash script to read from a file and execute commands

From Dev

Bash script to read from a file and execute commands

From Dev

How to get PID from within bash shell script

From Dev

How to execute shell script within a docker container

From Dev

How to execute the following commands in a bash script?

From Dev

Running MongoDB shell commands from within shell script connection refused

From Dev

How to execute a command within a bash script?

From Dev

How to execute library calls commands from shell?

From Dev

How to execute sudo commands with Expect & send commands in bash script?

From Dev

How to execute bash commands from C?

From Dev

How to execute mongo commands from bash?

From Dev

bash script, execute shell from another shell and assign results to a variable

From Dev

bash script, execute shell from another shell and assign results to a variable

From Dev

How to execute shell commands from Ruby in their own shell?

From Dev

How to execute shell commands from Ruby in their own shell?

From Dev

Execute gcloud commands in a bash script

From Dev

Bash script to spawn and execute commands

From Dev

How to execute linux commands in a remote machine with shell script

Related Related

  1. 1

    How to execute git commands from bash script?

  2. 2

    Shell out into zsh and execute commands from bash script

  3. 3

    How to execute commands in docker container as part of bash shell script

  4. 4

    How to execute an input asking utility in a loop within a shell script?

  5. 5

    Cannot execute shell commands in bash script

  6. 6

    How to execute a shell script from within an .app, and show it in the Terminal?

  7. 7

    how to execute a script within a script in shell command

  8. 8

    Can a bash shell script open a text file with less and then execute less commands from the script?

  9. 9

    How to execute the vim commands through shell script

  10. 10

    How to execute commands in gnuplot using shell script?

  11. 11

    how to execute compound commands in shell script?

  12. 12

    Bash script to read from a file and execute commands

  13. 13

    Bash script to read from a file and execute commands

  14. 14

    How to get PID from within bash shell script

  15. 15

    How to execute shell script within a docker container

  16. 16

    How to execute the following commands in a bash script?

  17. 17

    Running MongoDB shell commands from within shell script connection refused

  18. 18

    How to execute a command within a bash script?

  19. 19

    How to execute library calls commands from shell?

  20. 20

    How to execute sudo commands with Expect & send commands in bash script?

  21. 21

    How to execute bash commands from C?

  22. 22

    How to execute mongo commands from bash?

  23. 23

    bash script, execute shell from another shell and assign results to a variable

  24. 24

    bash script, execute shell from another shell and assign results to a variable

  25. 25

    How to execute shell commands from Ruby in their own shell?

  26. 26

    How to execute shell commands from Ruby in their own shell?

  27. 27

    Execute gcloud commands in a bash script

  28. 28

    Bash script to spawn and execute commands

  29. 29

    How to execute linux commands in a remote machine with shell script

HotTag

Archive