I wrote a burn-in program at Ubuntu which will be called automatically at start of system, as below. I expect it can trigger a re-start cycle but users can break that cycle at each iteration before the loop count is run out. It will prompt user to reboot or not by 'read' command. I inserted a few lines to call this burn-in program at end of /etc/rc.local, as below:
++++++++++++++++++++++++++
echo To test burn-in
echo To run burn-in
[ -e /home/lot/burn-in ] && bash /home/lot/burn-in
-----------------------------------------------
My trouble now is that the 'read' command can't receive my input key of 'n' or 'N'. Instead, the input seems gotten by bash and it interpreted it as a command. Below is the message appeared in console at system start.
+++++++++++++++++++++++
To test burn-in
To run burn-in
reboot or not? n
n: command not found
root@linaro-ubuntu-desktop:~# ttt =
------------------------------------------
If I invoked this program manually instead of being called at /etc/rc.local, the 'read' ran as well. So, my question is: how come 'read' can't get the input in case of being called /etc/rc.local?
Below is my burn-in program:
++++++++++++++++++++++++++++++++++
#!/bin/bash
#usage: burn-in 3
[ -z $1 ] && time=2
function infinite() {
[ ! -e /home/lot/count ] && echo "0" > /home/lot/count
declare -i count=$(cat /home/lot/count)
while true; do
echo "$[ $count+1 ]" > /home/lot/count
# /sbin/reboot
shutdown -r now
done
}
function finiteRun() {
[ ! -e /home/lot/count ] && echo "0" > /home/lot/count
declare -i count=$(cat /home/lot/count)
while [ $count -le $time ]
do
echo "$[ $count+1 ]" > /home/lot/count
echo "count = $count"
sleep 3
# /sbin/reboot
shutdown -r now
done
}
## to log restart time
echo -n "$count: " >> /home/lot/timelog
echo $(date +%Y/%m/%d-%H:%M:%S) >> /home/lot/timelog
## Main function stream
[ "$1" == infinite ] && {
infinite;
} || {
# read -p "reboot or not \(yY|nN\)?" -t 5 ttt
sleep 2
read -p "reboot or not? " -t 5 ttt
echo "ttt = $ttt"
[ "$ttt" == "n" ] && exit 0
[ "$ttt" == "N" ] && exit 0
finiteRun
}
exit 0;
I wrote a burn-in program at Ubuntu which will be called automatically at start of system, as below. I expect it can trigger a re-start cycle but users can break that cycle at each iteration before the loop count is run out. It will prompt user to reboot or not by 'read' command. I inserted a few lines to call this burn-in program at end of /etc/rc.local, as below:
++++++++++++++++++++++++++
echo To test burn-in
echo To run burn-in
[ -e /home/lot/burn-in ] && bash /home/lot/burn-in
-----------------------------------------------
My trouble now is that the 'read' command can't receive my input key of 'n' or 'N'. Instead, the input seems gotten by bash and it interpreted it as a command. Below is the message appeared in console at system start.
+++++++++++++++++++++++
To test burn-in
To run burn-in
reboot or not? n
n: command not found
root@linaro-ubuntu-desktop:~# ttt =
------------------------------------------
If I invoked this program manually instead of being called at /etc/rc.local, the 'read' did as expected. So, my question is: how come 'read' can't get the input in case of being called /etc/rc.local?
Below is my burn-in program:
++++++++++++++++++++++++++++++++++
#!/bin/bash
#usage: burn-in 3
[ -z $1 ] && time=2
function infinite() {
[ ! -e /home/lot/count ] && echo "0" > /home/lot/count
declare -i count=$(cat /home/lot/count)
while true; do
echo "$[ $count+1 ]" > /home/lot/count
# /sbin/reboot
shutdown -r now
done
}
function finiteRun() {
[ ! -e /home/lot/count ] && echo "0" > /home/lot/count
declare -i count=$(cat /home/lot/count)
while [ $count -le $time ]
do
echo "$[ $count+1 ]" > /home/lot/count
echo "count = $count"
sleep 3
# /sbin/reboot
shutdown -r now
done
}
## to log restart time
echo -n "$count: " >> /home/lot/timelog
echo $(date +%Y/%m/%d-%H:%M:%S) >> /home/lot/timelog
## Main function stream
[ "$1" == infinite ] && {
infinite;
} || {
# read -p "reboot or not \(yY|nN\)?" -t 5 ttt
sleep 2
read -p "reboot or not? " -t 5 ttt
echo "ttt = $ttt"
[ "$ttt" == "n" ] && exit 0
[ "$ttt" == "N" ] && exit 0
finiteRun
}
---------------------------------------------------------