LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-29-2011, 07:51 AM   #1
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 88

Rep: Reputation: 4
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.

Last edited by lonesoac0; 09-29-2011 at 07:59 AM. Reason: more info
 
Old 09-29-2011, 08:20 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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
 
Old 09-29-2011, 12:17 PM   #3
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 88

Original Poster
Rep: Reputation: 4
Thank you soo much! It works just like a charm!
 
Old 09-29-2011, 12:20 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You're welcome!
 
Old 09-30-2011, 10:30 PM   #5
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 88

Original Poster
Rep: Reputation: 4
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

Last edited by colucix; 10-02-2011 at 12:49 PM. Reason: corrected code tags (inverted slash) and removed dupe
 
Old 10-02-2011, 12:59 PM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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.
 
1 members found this post helpful.
Old 10-02-2011, 03:20 PM   #7
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 88

Original Poster
Rep: Reputation: 4
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
 
  


Reply

Tags
scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
launching an installed application in hardy raphtor Linux - Newbie 8 04-12-2009 02:23 AM
Launching application + variables in FVWM Peff Linux - Software 2 06-28-2005 09:36 AM
launching a program from a C++ application Error1312 Programming 7 02-25-2004 09:18 AM
Launching application when gnome startups appel Linux - Software 3 08-02-2003 11:06 PM
launching an application when X starts... DKnight Linux - Newbie 13 06-08-2003 08:43 AM


All times are GMT -5. The time now is 10:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration