2

I'm trying to write a bash script on Raspbian that will open a video URL in fullscreen, wait 2 minutes, then close the window

#!/bin/bash
chromium-browser <url> --start-fullscreen
sleep 120
pkill chromium

However, the code won't kill the chromium window.

3 Answers 3

3

Another simple method

timeout 120 chromium-browser https://raspberrypi.stackexchange.com
2

Here's the problem:

chromium-browser <url> --start-fullscreen

That command will run forever until the user closes the window.
Same reason why running this command in the terminal will not return you to the prompt (pi@raspberrypi:~ $) until the command is finished. In other words, the script never reaches the further lines in your script, but is stuck there.

To start the command, then move on, just add a & to the chromium-browser command. Like this:

chromium-browser <url> --start-fullscreen &

Bash will start this command, then go to to the next one.

1

Try using pkill with the process ID, which can be found like this

pid = pidof <process name>

The process ID has been assigned to the variable pid. Then just use pkill with that variable

pkill pid
2
  • will the process ID be changed with each new instance of chromium being opened?
    – A.Collins
    Commented May 20, 2017 at 15:31
  • Most likely, yes.
    – Joe
    Commented May 20, 2017 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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