Bash script to open chrome, then turn off the computer when chrome is closed

I would like to write a startup script in bash to make ubuntu more friendly for grandfather.

The script should:

open chrome wait until chrome shuts down turn off the computer

still i

#!/bin/bash
if [ -z "$1" ]; then
    address="http:\\www.google.co.uk"
else
    address=$1
fi

echo starting the internet
google-chrome $address

while [ 1=1 ];
do
   grep_resp=$(ps aux | grep chrome)
   if [ -z "$grep_resp" ]; then
       echo turning computer off 
   else
       echo chrome still running
   fi
   sleep 5
done 

but grep for "chrome" is in the process list

Any help?

+3
source share
3 answers

You get this error because $grep_respin this ...

if [ -z $grep_resp ]; then

... is probably decrypted into a string containing spaces. If you put quotation marks there:

  if [ -z "$grep_resp" ]; then

He will do what you expect. However, I think all this may be unnecessary. Chrome does not automatically create a background or something else when it starts, so you should do this:

google-chrome $address
echo turning computer off
...
+3
source

What about:

#!/bin/bash

user=gramps

sudo -u "$user" -- chrome "$1"; shutdown -P now

script root.

+1

14

if [ -z "$grep_resp" ]; then

, .

+1

All Articles