Header Shadow Image


How to create a for loop to print a sequence or range of numbers on DD-WRT or busybox devices: Linux

DD-WRT run what's known as a busybox, which is a single tiny executable designed to run on enbedded devices.  busybox provides common UNIX utilities normally found on larger UNIX / Linux installations such as desktop computers.  Unfortunately it's limited and even with the shell it provides, alot of functionality such as common shell loops no longer function as expected or the syntax is simply not supported.   So none of these would work:

for KEY in $(cat /var/log/messages); do print "something"; done

for KEY in 1 2 3 4 5 6 7 8; do print $KEY; done

for KEY in 1 .. 1000; do print $KEY; done

Here's how to create a for loop to print a sequence or range of numbers on DD-WRT or busybox devices:

# for i in $(awk 'BEGIN { for ( i=0; i<10000; i++ ) { print i; } }'); do sleep 5; dmes
g|grep -v PROTO; done

Should also work equally well on /bin/ksh or /bin/bash shells as well as the /bin/sh shell available.  The above line will monitor dmesg log file excluding firewall log lines.

Cheers,
TK

Leave a Reply

You must be logged in to post a comment.


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License