LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 01-15-2004, 05:17 PM   #1
djidji
LQ Newbie
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Arch
Posts: 27

Rep: Reputation: 15
launching xmms with cron


anybody knows how to do it? i issue the command to start xmms and i pass a list with songs to it that i want to be played. if i have xmms already open it works fine, the list is loaded and the music is playing. however if i did not have xmms running already this is the response that i get:

** CRITICAL **: Unable to open display

anybody knows how to go around this?
 
Old 01-15-2004, 06:31 PM   #2
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
With most cron processes, the environment needs to be set, in this case. For example, in
cron.daily, logrotate is a script that contains...

#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf

the require environment to execute this is /bin/sh. If you want to spawn xmms, then you will also have to tell it how to connect to X, since this will not be set up. It MIGHT be picked up by creating the script like this....

#!/bin/sh
xmms --playlist (Or whatever syntax you are using).

You will have to leave X running, however, something like this should work...
Script xmmsplay in desired cron directory...

#!/bin/sh
export DISPLAY=localhost:1
xmms --playlist (Or whatever syntax you are using).

R.O.

P.S. The reason it works when already running is because you have the option 'Allow only one instance to run', and it simply connects to the existing process.
 
Old 01-15-2004, 07:22 PM   #3
djidji
LQ Newbie
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Arch
Posts: 27

Original Poster
Rep: Reputation: 15
hmmmm... i tried doing what you suggested but nothing happened. this is the script that i have:

#!/bin/bash
export DISPLAY=localhost:1
/usr/local/bin/xmms list.m3u &


this does not work through cron nor does it work if i just try and run the scrip. and i did have x running...

help...
 
Old 01-15-2004, 07:34 PM   #4
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
Hmmm, well, my xmms is in
/usr/bin/xmms
DOH!. I use VNC way to much, it isn't :1, this works for me in a console...

#!/bin/bash
export DISPLAY=:0.0
/usr/bin/xmms list.m3u &

although I don't have list.3mu available for playing. Do you need to specify the whole path for list.3mu?

R.O.

P.S. Sorry about the :1, it was trying to connect to the second X session, which is not typically running.
 
Old 01-15-2004, 07:44 PM   #5
djidji
LQ Newbie
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Arch
Posts: 27

Original Poster
Rep: Reputation: 15
thanks for taking your time to help me out... here is the news:

with :0 i get it to work if i just run the script. but when i run it through cron i get the message (e-mail):

Xlib: connection to "localhost:0.0" refused by server
Xlib: No protocol specified

thanks again...
 
Old 01-15-2004, 07:52 PM   #6
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
Alrighty then...
try

xhost + localhost

as the user, then try again. I don't know why root is not allowed to connect to the X session, which is how cron runs...but these things happen. If it works, then you can add
xhost +
to the end of
/etc/rc.local
file and the command is executed each time X starts as a user.

But first things first, try the above.

R.O.
 
Old 01-15-2004, 08:04 PM   #7
djidji
LQ Newbie
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Arch
Posts: 27

Original Poster
Rep: Reputation: 15
WOW! it works! ("it's alive! it's alive"). it starts without the playlist or eq but that is really not important. not if i can bug you for a minute more to explain to me what is the command:

xhost + localhost

and is this something i can run every time as a part of my script so that this works all of the time? again, thanks a lot for your help.

p.s. now i got my alarm clock working! :-)
 
Old 01-15-2004, 08:28 PM   #8
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
No, xhost + is the way the owner of the current X session can block or allow other users to connect to the X session. For example, if I wanted to 'push' a picture to your workstation (PC), then I could
export DISPLAY=YourIP:0
then xv <picture>

You can block or allow this with xhost + <MyIP> or xhost - <MyIP>. That is why I suggested that you put it as the last line in
/etc/rc.local

Then, whomever logs into the PC as any user, xhost + localhost will be executed automatically.

Looking at the options, xmms --help, shows that you can specify
xmms -p and it will start playing the current playlist. The reason it isn't starting the playlist or equilizer is du to it starting as root, and you haven't opened them as root, and then exited. Cron runs as root, you use xmms, normally, as a regular user.

Hey, try this, if you usually log in as a single user other than root, such as 'Steve'

#!/bin/bash
export DISPLAY=:0.0
su - Steve -c '/usr/bin/xmms -p'

Then it will start playing whatever was loaded when you last exited, and you aren't running xmms as root (a VERY small security breach), and you won't need the xhost + at all, case Steve owns the X session.

R.O.


R.O.
 
Old 01-15-2004, 08:33 PM   #9
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
P.S. localhost is the name from your /etc/hosts that is linked to the IP of your machine. You could just as easily done
xhost + 127.0.0.1

su - username -c 'command to execute'
means that change to user 'username', and execute the command in these quotes. Since root is the one doing the su, no password is required.

R.O.
 
Old 01-15-2004, 08:55 PM   #10
djidji
LQ Newbie
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Arch
Posts: 27

Original Poster
Rep: Reputation: 15
thanks! thanks! thanks!.......

one thing:
"Cron runs as root, you use xmms, normally, as a regular user."

while trying to get this working i was logged on as root. (and i had started xmms as root before.) how come root did not have the rights to connect to x session?
 
Old 01-15-2004, 08:59 PM   #11
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
Well, like I said, some things just make you go hmmmm? Has to be something with the cron load environment. There is a reason, but I don't know what it is, just how to get around it. So, as regualr user, maybe try logging out and back in, to see if you do need the 'xhost + localhost'. It really can't hurt to add it to your
/etc/rc.local file though, so this kind of thing doesn't happen again.

R.O.
 
Old 01-15-2004, 09:02 PM   #12
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
Oh Yeah, don't forget to add
& to the su;ed command, or else cron will hang there on that script not exiting.

su - Steve -c '/usr/bin/xmms -p &'

That would have been great. You had the & at the beginning, but I forgot to re-add it.

R.O.
 
Old 01-15-2004, 09:09 PM   #13
djidji
LQ Newbie
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Arch
Posts: 27

Original Poster
Rep: Reputation: 15
thanks again...
 
  


Reply



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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
No More Cron Mail, Cron Error? Xhost Linux - General 3 07-26-2004 04:28 PM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM
I get following output to xterm when launching xmms ... purpleburple Linux - General 11 07-26-2002 06:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 12:46 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration