LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Launching application (http://www.linuxquestions.org/questions/linux-newbie-8/launching-application-905587/)

lonesoac0 09-29-2011 07:51 AM

Launching application
 
Hello all,

I am trying to figure out how to make a script that first looks for any running instance of Feh or Mplayer. If no feh or mplayer is running then feh will run.

Here is what I have so far:
Code:

#!/bin/sh
FKEIHL1=$(ps -A | grep -w mplayer | awk '{print $4}')
if [ "$FKEIHL1" != "mplayer" ]
env DISPLAY=:0 mplayer -shuffle -loop 0 -fs /DIR/PATH/* &
exit 0
fi

I also want mplayer to launch if there are no running instances of either feh or mplayer.

colucix 09-29-2011 08:20 AM

What about something like this?
Code:

if ! ps -C feh > /dev/null
then
  if ! ps -C mplayer > /dev/null
  then
    echo no running sessions of feh or mplayer
  fi
fi


lonesoac0 09-29-2011 12:17 PM

Thank you soo much! It works just like a charm!

colucix 09-29-2011 12:20 PM

You're welcome!

lonesoac0 09-30-2011 10:30 PM

I am running into an issue, if I do not have any files in the directory then the application keeps looping. I would like for the application mplayer not to launch if it does not find specific files like MOV, flv, or avi.
Code:

#!/bin/sh
if ! ps -C feh > /dev/null
 then
  if ! ps -C mplayer > /dev/null
  then
    env DiSPLAY=:0 mplayer -shuffle -loop 0 -fs /DIR/DIR/* &
  fi
fi
exit 0


colucix 10-02-2011 12:59 PM

It hangs because of the -loop 0 option that tries to open non-existent files forever. You can either remove -loop or assign a number of iterations different from 0. Otherwise check the existence of *.mov, *.avi or *.flv files immediately before running mplayer, example:
Code:

if ls *.[Aa][Vv][Ii] > /dev/null 2>&1 || ls *.[Ff][Ll][Vv] > /dev/null 2>&1 || ls *.[Mm][Oo][Vv] > /dev/null 2>&1
then
  mplayer -loop blah blah here
fi

Hope this helps.

lonesoac0 10-02-2011 03:20 PM

Yo! You are the man! The only thing that I had to add was a variable for the directory containing the files. It is really great to know how to check for file in directories before an application launches too!

Code:

var=/dir/dir/
if ls $var*.[Aa][Vv][Ii] > /dev/null 2>&1



---------- Post added 10-02-11 at 02:20 PM ----------

Yo! You are the man! The only thing that I had to add was a variable for the directory containing the files. It is really great to know how to check for file in directories before an application launches too!

Code:

var=/dir/dir/
if ls $var*.[Aa][Vv][Ii] > /dev/null 2>&1



All times are GMT -5. The time now is 07:20 PM.