nohepe
Posts: 5
Joined: Sun Oct 11, 2015 8:45 pm

Running LXterminal windows from shell script

Sun Oct 11, 2015 8:56 pm

Hello, I would like to run this script every 5 minutes. It checks needed procesess and start them if they are not running. I need to run mopidy and deluge-web in new lxterminal window. When I try to run this script from terminal, it works without problem. Howewer when this script is scheduled from crontab it only starts deluged(beceuse it is daemon) and nothing more. Script:

Code: Select all

#!/bin/bash
mopidy_state=`ps -e | grep "mopidy"`
if [ "$mopidy_state" == "" ]; 
then
 sudo lxterminal -e mopidy
else echo "mopidy is running correctly"
fi

deluged_state=`ps -e | grep "deluged"`
if [ "$deluged_state" == "" ]; 
then
 deluged
else echo "deluged is running correctly"
fi

delugeweb_state=`ps -e | grep "deluge-web"`
if [ "$delugeweb_state" == "" ]; 
then
 sudo lxterminal -e deluge-web
else echo "deluge-web is running correctly"
fi
Alternatively it could be started from some kind of start script after boot. But I would like to have it like this, because it handle also situations when process abnormaly falls/abends without restart of Pi.

Thank you.

W. H. Heydt
Posts: 12785
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Running LXterminal windows from shell script

Mon Oct 12, 2015 2:35 am

Read the manual page on "cron". That is, "man cron" and, probably, "man crontab". Cron is the system "job" scheduler.

nohepe
Posts: 5
Joined: Sun Oct 11, 2015 8:45 pm

Re: Running LXterminal windows from shell script

Mon Oct 19, 2015 8:58 pm

I havent problem with scheduling, but I am not able to start process from script in new terminal window.

For example when I use command:

ps -e

I need those proceses from script started with TTY pts/1 (or any number instead of 1).

If I dont start them in new window, then they are started with TTY ? and thats useless for me.

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Running LXterminal windows from shell script

Tue Oct 20, 2015 5:25 am

You can't (easily) schedule a task with cron to pop up in a terminal window on a GUI session. Cron is for running system tasks in the background. They always have a TTY of "?" as they don't run in a terminal.

You might want to consider writing something that auto starts when you log in to the desktop and sits in the background triggering your tasks as needed.

Return to “Beginners”