Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I am new to bash and need help badly.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
it works thanks,but any way to run this script on ram or something that even if i close terminal emulator it keeps running comments –  Roshan singh Jul 21 at 14:38
    
@Roshansingh for closing terminal without killing command, visit this –  Pandya Jul 21 at 16:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.