Have troubles with bash script: xubuntu systemd.link onboard

Hey there.
I'm new in write bash scripts in fact this is my first one so please be patient ;). Also english is not my native language but i hope you understand me anyway.

I installed xubuntu on my mothers laptop and every time a new version update gets installed the keyboard doesn't work anymore

i had to reconfigure it by

So to get her the possibility to solve this problem by her self i wrote a small bash script to enable onboard keyboard (to input sudo password & menu navigation) and run this specific command.

#!/bin/bash
onboard
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration"
killall onboard

The problem i got is that the terminal isn't open all the time. Most time i have to run the script twice then the terminal shows up. I guess i've done a really simple mistake which i just can't see yet.

How can i solve this or is there maybe a more simple way to solve it?

Greetings & Thanks for your help
Apop

---------- Post updated 1st Mar 2017 at 08:49 AM ---------- Previous update was 28th Feb 2017 at 06:11 PM ----------

Tried out some things now like run the onboard command in a seperate instance with
"onboard $" but didn't help.

I also tried

onboard; xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration"

It just feels like the bash "script" gots stuck after executing a command.

The way i want it to work is

  1. Open onboard keyboard
  2. Open terminal and execute keyboard reconfiguration / or alternative solution for the "keyboard not working after update"-problem
  3. After the reconfiguration close keyboard
  4. EOF

The best result i got so far is

#!/bin/bash
set -e
onboard
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration"
killall onboard
killall reconfig
exit 0

Almost working but still i need to run it at least twice to get both commands be executed.

Can I suggest running the onboard command in the background with & like this:

#!/bin/bash
onboard &
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration"
killall onboard
killall reconfig
exit 0
1 Like

Have tried this but if i run onboard in the background the keyboard don't shows up. Only the terminal opens in this case.

I also tried the while command just for try&error but don't figured out yet how to exit the loop without repeating it.

#!/bin/bash
while onboard
do xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration"
done
killall onboard
killall reconfig
exit 0

Edit:

if i run the onboard command in the terminal i get following message and the window gets blocked (no other commands possible):

might this cause this problem?

---------- Post updated at 07:52 PM ---------- Previous update was at 06:42 PM ----------

Ok solved the "onboard problem" with using exec. Now both commands runs all the time but now the keyboard isn't closing after the reconfiguration is done.

#!/bin/bash
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration" &
exec onboard
killall onboard
killall testrun
exit 0

How can i loop a if command like this at the end?

if ! pgrep -x "xfce4-terminal" > /dev/null
then
       killall onboard
fi

As the terminal get closed by itself after the reconfiguration i thought about to check if the terminal still is open and if not close keyboard.

Sorry for all those noob questions :wink:

Try running terminal in the background and then waiting for it before killing the popup like this:

#!/bin/bash
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration" &
onboard
wait
killall onboard
killall testrun
exit 0

Hm nope onboard is still running with this solution

We could try looping with:

#!/bin/bash
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration" &
onboard
while pgrep -x "xfce4-terminal" > /dev/null
do
    sleep 0.5
done
killall onboard

or prehaps this:

#!/bin/bash
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration" &
onboard
while pgrep -x "dpkg-reconfigure" > /dev/null
do
    sleep 0.5
done
killall onboard

I will try it. I also checked the output of bash -x and i saw that the script seems to stop after executing onboard. I had some echoes at the end but they didn't get printed.

bash -x testrun
+ exec onboard
+ xfce4-terminal -e 'sudo dpkg-reconfigure keyboard-configuration'
21:02:47.517 WARNING Config: mousetweaks GSettings schema not found, mousetweaks integration disabled.

---------- Post updated at 03:11 PM ---------- Previous update was at 03:07 PM ----------

Nope same problem with the loop. Script get stopped after executing onboard command

EDIT:
I wrote also in the ubuntuforums for help with the onboard command as it is related to ubuntu in the software center i hoped they may can help me out with this :slight_smile: But forum seems to be inactive since january 17

Troubles with starting onboard keyboard with bash script

If you are using exec the script will not continue as exec replaces the shell with the command you specify.

2 Likes

Ah ok good to know. I removed exec but still get same bash -x output

.
bash -x testrun
+ onboard
+ xfce4-terminal -e 'sudo dpkg-reconfigure keyboard-configuration'
21:36:42.063 WARNING Config: mousetweaks GSettings schema not found, mousetweaks integration disabled.

I guess I will try to run onboard in a seperate process with a second file. It feels not very efficient to create 2 files for this small script but I guess this should at least work.

So managed now to get it work

#!/bin/bash
#filename=testrun
script_name=$0
script_full_path=$(dirname "$0")

$script_full_path/onboard_run &
xfce4-terminal -e "sudo dpkg-reconfigure keyboard-configuration" &

while pgrep -x "xfce4-terminal" > /dev/null
do
    sleep 0.5
done

killall onboard
killall testrun
exit 0
#!/bin/bash
#filename=onboard_run
onboard
exit 0

Thx Chubler_XL for your help.