0

I have a Pi that is running a .sh script on startup which opens 2 applications a industrial SCADA followed by Iceweasel. I would like to switch between the 2 apps every 30 seconds. I used the following script to do it manually.

#!usr/bin/sh
wmctrl -a "icewasel"
sleep 30
wmctrl -a "window2"

The using "watch" to run that script every 30 seconds:

watch -n 30 sh /home/pi/rotate.sh

When I try to add the above line to my start up start.sh script nothing happens. It is as follows:

#!usr/bin/sh
"/home/pi/clientlauncher.sh"
sleep 20
iceweasel
sleep 20
watch -n 30 sh /home/pi/rotate.sh

Everything up to the "watch" commands starts and runs fine but it does not work. Any suggestions? Thanks in advance!

1

You're running a script every 30 seconds that switches to icewasel (should that be iceweasel ) then 30 seconds later it switches to window2, at which point the watch program kicks in and runs the script which switches it back to icewasel ... do you see the problem?

By the way, your shebang looks wrong ... it should be something like #!/bin/sh as usr/bin/sh is not a valid program

Unless you need to watch the output of your rotate.sh script, the use of watch is inappropriate for this task

Change your start.sh as follows:

#!/bin/sh
(
    /home/pi/clientlauncher.sh
    sleep 20
    iceweasel
    while $(true)
    do
        sleep 30
        wmctrl -a "iceweasel"
        sleep 30
        wmctrl -a "window2"
    done
)&

This forks a script into the background that launches the two programs and switches between them every 30 seconds - no need for the ill-conceived use of watch + another shell script

  • Thanks for your time, mate! The script works fine but only when I run it from lxterminal like: sudo sh /hompe/pi/start.sh I have a line in /etc/xdg/lxsession/LXDE-pi/autostart that states calls the script @sudo sh /home/pi/start.sh On startup the script will run but will only open the windows without executing the while loop. Any ideas? – Ivan Ivanov Jun 27 '16 at 15:05
  • if you're running it sudo and/or through cron, it may not be able to open a window as it won't know which X display to write to. – scruss Jun 27 '16 at 16:17
  • The script runs fine but not straight from start up. I need to close iceweasel and open it manually for the while loop to start working. – Ivan Ivanov Jun 28 '16 at 11:07
  • All working now. I needed to stop iceweasel in the script so I can move to the next line. – Ivan Ivanov Jun 28 '16 at 15:22

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.