0

I am writing a bash script and am checking whether the application is running. If it is not running it should be started in a separate process (not a child process). If it is running, the window should be maximized. I kind of made it but the new process terminates shortly after being started, probably because the script process ends.

#!/bin/bash
if (ps aux | grep App1 | grep -v grep > /dev/null)
then
    echo App1 is running
    wmctrl -x -r WMClassOfApp1 -b "add,maximized_vert,maximized_horz"
else
    echo App1 is not running
    sh -c /usr/bin/app1 & disown # This app should be started in a separate process and not terminate
fi

I probably have to add that I am calling this script from a udev rule. When I execute it in a terminal, it works fine. When I call it from the udev rule, the app1 terminates.

Dominique
  • 16,450
  • 15
  • 56
  • 112
neolith
  • 699
  • 1
  • 11
  • 20
  • Does this answer your question? [Best way to make a shell script daemon?](https://stackoverflow.com/questions/3430330/best-way-to-make-a-shell-script-daemon) – Jon Sep 24 '20 at 07:38
  • No I already tried nohup before. It has the same outcome. It works from the terminal, but not from udev. – neolith Sep 24 '20 at 09:05

1 Answers1

0

A bash script is not the right solution for this: best is to add this to crontab of your system.

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • I want to call this from a udev rule that checks if a device is connected. Doing this with crontab is a periodic call as far as I understand. The script does its job, but calling it from udev seems to be the problem. – neolith Sep 23 '20 at 22:07
  • @neolith: therefore I have added the "udev" tag to your question, this might cause followers of this tag to detect your question more easily. – Dominique Sep 24 '20 at 07:35