devi
Posts: 2
Joined: Sun Jun 22, 2014 8:36 pm

Stop an infinite loop

Sun Jun 22, 2014 8:54 pm

Hi everyone,

(excuse me for my bad english)

I can't get out of an infinite loop.
The problem is that when the Pi is booting, it execute a command in my autostart script (/etc/xdg/lxsession/LXDE/autostart) :

@sh /home/pi/videoplayer.sh


The videoplayer script read with omxplayer a video playlist in the directory /home/pi/videos
There is the script videoplayer.sh :

#!/bin/sh

# get rid of the cursor so we don't see it when videos are running
setterm -cursor off

# set here the path to the directory containing your videos
VIDEOPATH="/home/pi/videos"

# you can normally leave this alone
SERVICE="omxplayer"

# now for our infinite loop!
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
sleep 1;
else
for entry in $VIDEOPATH/*
do
clear
omxplayer $entry > /dev/null
done
fi
done


I tried CTRL+C, CTRL+X, ALT+F4 ... and many combinaisons but the endless loop doesn't stop while the Pi is unpowered.

Any help would be grateful,
Devi

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Stop an infinite loop

Sun Jun 22, 2014 9:36 pm

Do you have a keyboard and screen attached to the Pi?

If so put the SD card in another machine and edit /boot/cmdline.txt.

Append init=/bin/sh at the end of cmdline.txt. Put the SD card back in the Pi and reboot.

Make the needed changes and then undo the change to /boot/cmdline.txt.

devi
Posts: 2
Joined: Sun Jun 22, 2014 8:36 pm

Re: Stop an infinite loop

Sun Jun 22, 2014 9:47 pm

I change the /boot/cmdline.txt file and I am able to modify my videoplayer script.
I am a beginner in shell scripts and I would like to know if there is a way to add something in my videoplayer script to stop the loop ?

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Stop an infinite loop

Sun Jun 22, 2014 10:30 pm

sudo killall videoplayer.sh

Return to “Advanced users”