Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm stomped on how to accomplish this task. I need to run this script that fills up the nand flash on an embedded (linux-Busybox v1) device with random data, then continually repeats this process until the user stops it or the flash drive fails. The problem I'm having is that my testing involves power-cycling the device several times. But, the script stops running, which calls for me to start it again manually. Can someone recommend a resolution? Thanks!

Script:

#!/bin/sh

mkdir -p /mytest/storage/testnand

idx=0
while true
do
#./script.sh >/mytest/storage/testnand/test.raw
dd if=/dev/urandom of=/mytest/storage/testnand/test.raw bs=100000 count=50 2> /dev/null
if [ ! $? = 0 ]
then
    echo "ERROR: ${idx}"
    echo "ERROR: ${idx}" >> /mytest/storage/testnand/error.log
    continue
fi
cp /mytest/storage/testnand/test.raw /mytest/storage/testnand/test_copied.raw
if [ ! $? = 0 ]
then
    echo "ERROR 1: ${idx}"
    echo "ERROR 1: ${idx}" >> /mytest/storage/testnand/error.log
    continue
fi
cmp /mytest/storage/testnand/test.raw /mytest/storage/testnand/test_copied.raw 2> /dev/null
if [ ! $? = 0 ]
then
    echo "ERROR 2: ${idx}"
    echo "ERROR 2: ${idx}" >> /mytest/storage/testnand/error.log
    continue
fi
echo "OK ${idx}"
echo "OK ${idx}" >> /mytest/storage/testnand/ok.log

idx=`expr $idx + 1`
done

Update:

I failed to mention, as I didn't have this information at the time, the embedded os is patched: there are many files that are read-only; /etc/rc is one of those files. Is there some kind of work-around that will allow me to run my script at start-up?

share|improve this question

1 Answer 1

You could add the following to /etc/rc.local:

sudo -u ${USERNAME-TO-RUN-AS} tmux new-session -d -s ${NAME-FOR-SESSION} -d 'sh /path/to/your/script'

Then you can type "tmux attach namefortmuxsession" to view the terminal output from your script.

Replacing /path/to/your/script',$(USERNAME-TO-RUN-AS)and${NAME-FOR-SESSION}` to suit you needs.

Of course, you'll need tmux installed. You could probably do this with screen instead, however I prefer tmux.

share|improve this answer

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.