the script is called from /home/pi/.config/lxsessions/LXDE-pi/autostart with the line:

@bash /home/pi/Documents/openContent.sh   /media/pi   index.html   http:/google.com

and openContent.sh is:

# $1 defines path we search
# $2 defines name of file we're searching for
# $3 defines default URL if we can't find the thing we're searching for
path="$(find $1 -name $2 | head -n 1)"
if [ -f "$path" ]; then
  echo "content found at $path"
  chromium-browser --incognito --kiosk $path
  echo "content was not found in $1
  chromium-browser --incognito --kiosk $3

When i run the script from terminal after startup, it works as expected. If i search with the same arguments, it will open the webpage from USB. If i give it a random name to search for that isn't there, it will open google.com (since it can't find it in /media/pi. That's all good

However, when rebooting and running from autorun, it will invariably go to google.com. If i substitute the line:

@sh /home/pi/Documents/openContent.sh   /media/pi   index.html   http:/google.com


@chromium-browser --incognito --kiosk /media/pi/DISK_IMG/index.html

it opens the page - so it doesn't seem to be an issue of the USB drive loading late or I would expect neither to work.

I figure that this is just something i'm doing wrong with the bash script or passing arguments in the autostart, but I don't know what. Any ideas?


I tried adding a sleep 30 to the top of openContent.sh and it worked. this is a little disturbing because I really don't want to hard-code a delay in there. Is this a known issue with find/ USB devices, that they load some time after the GUI/desktop environment?

It kind of makes sense because basically chromium can't actually try looking at the dir until the file system is ready, so if i pass it an explicit URL, it'll trust me and go there and by the time it gets around to looking there, the file system is ready, but if i search first, the results tell me there's nothing there.

  • 1
    The shebang is wrong. You are running the script as a sh script and not as a bash script. I am not sure that is the source of your issues, but you should start ruling errors out – Bruno9779 Feb 17 '17 at 15:43
  • 1
    Have you tried logging $1 $2 $3 and $path to a file and seeing if something is weird? Something like @bash -x /home/pi/Documents/openContent.sh /media/pi index.html http:/google.com &> /tmp/openContent.log – Zachary Brady Feb 17 '17 at 16:07
  • awesome thanks for the suggestions. I'll try what you recommended zachary and post the results of the log and bruno, I caught this just after posting and corrected it, but had the same results also @ both, I put an edit above after trying something, maybe this changes things? – OtterFamily Feb 17 '17 at 16:13
  • is /media/pi/DISK_IMG mounted prior to this script running or does this script run first? Just change around the order of execution. – jiveturkey Feb 17 '17 at 20:01
  • the problem is that I can't count on the naming scheme - in some cases, there will be a number appended to the disk especially if a client disconnects usb drives improperly, and i can't count in the device id because that might change, so I don't actually mount the drive explicitly, I just rely on raspbian's default mounting behavior. As a result I think that the script runs inconsistently first – OtterFamily Feb 20 '17 at 11:34

So it seems that there just is a delay between the execution of /home/pi/.config/lxsessions/LXDE-pi/autostart and the automatic mounting of any drives, so I modified my bash script to try for the first minute to find the file, then fallback to a default. This usually triggers within the first few seconds, so it's not too dirty and not too long.

I think the reason that calling a specific URL worked, but trying to find it on startup didnt, is because the delay between chromium launching, and the file system checking for mounted drives is about the same, so by the time that chrome launches, the URL given to chrome is valid. Whereas when doing a find operation, it happens a lot faster, and returns null before the file system can mount drives, so then chrome is opened with the default URL.

The following code could probably be optimized by opening the default as the first action, and then trying to find the real file, killing chrome when successful, and relaunching with the right URL, but for now this works:

# $1 Defines the path that we will look in
# $2 Defines the name of the file we're looking for
# $3 Defines the path to a default file if not found


for i in {0..60}
  path="$(find $1 -name $2 | head -n 1)"
  if [ -f "$path" ];then
   echo "content found at $path"
   chromium-browser --incognito --kiosk $path
   echo "content was not found on attempt $i"
   sleep $delayTime

chromium-browser --incognito --kiosk $3
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.