0

i have a script in /etc/init.d name: vinh.sh used to call another sript, Its contents are as follows:

#!/bin/bash
cd /media/usb/demo
source ./list.sh

and contents of list.sh:

#!/bin/bash
cd /home/pi/matrix
while true; do
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/1.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/2.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/3.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/4.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/5.gif
sudo timeout 30 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/6.gif
sudo timeout 30 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/7.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/8.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/9.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/10.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/11.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/12.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/13.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/14.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/15.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/16.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/17.gif
sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/18.gif
sudo timeout 15 bash -c '(while :; do date +%T ; sleep 0.2 ; done) | sudo ./text-example -f fonts/10x20.bdf -v fonts/7x13.bdf -x57 -y35 -r 32 -c 6 -P 3 -C0,0,255'
done

when i run vinh.sh manual (. ./vinh.sh) it run perfectly but when it boot, it run to sudo timeout 20 ./led-image-viewer -r 32 -c 6 -P 3 -b 70 /media/usb/demo/10.gif and stop working.

Pham Vinh
  • 3
  • 1

1 Answers1

0

Services started from init must either exit quickly -- within a few seconds -- or else fork to the background.

The normal way to do this from within a shell script is via &, although it will not work with source, so what your wrapper script should do is

#!/bin/sh

/media/usb/demo/list.sh &

If you start this from a terminal it should also work but will return right away; if you start it remotely and exit it will die mysteriously eventually unless you use (preferrably) setsid or nohup, but this is not necessary in init scripts.

This Q&A may be useful with regard to logging output and/or debugging problems.

Beware that if you are putting that wrapper in /etc/init.d and using the old SysV style update-rc.d methodology or something similar your script does not appear compliant which may also cause problems. Since it is fairly straightforward I recommend you just place that line (/media/usb/demo/list.sh &) in /etc/rc.local instead.

goldilocks
  • 58,859
  • 17
  • 112
  • 227
  • i have put /media/usb/demo/list.sh & in /etc/rc.local but it's not work then i use putty to run it manual it's return pi@raspberrypi:/media/usb $ /media/usb/demo/list.sh & [1] 775 -bash: /media/usb/demo/list.sh: Permission denied I have tried sudo /media/usb/demo/list.sh & and run it with root privileges it stil return the same problem – Pham Vinh Aug 01 '16 at 00:50
  • It needs to be executable: sudo chmod 755 /media/usb/demo/list.sh. It will work without that via source, so perhaps you did not have it set that way before. Note that 755 = world executable/readable, but writable only by owner (most things in bin directories are this way), so if you want to place more restrictions on it than that you will have to use a different value. – goldilocks Aug 01 '16 at 10:44