PDA

View Full Version : using task schedular?



woedend
11th July 2005, 02:41 AM
All I need now is a good working task scheduler to get rid of...windows. The default one doesn't work for me...i add the task, make sure it works by running it,,,but at the specified time nothing happens. I basically need xmms to play 2 different songs at 2 different times as an alarm clock every day...thats all. Anyone who can help?

shams
11th July 2005, 03:12 AM
are you about linux? for linux use cronjobs

crackers
11th July 2005, 03:42 AM
You can't run a GUI program via cron - there's no "X" display to use (even if you're "in" the UI). You can leave XMMS running on the UI session and use a cronjob to run the xmms command-line controls (see the man page). Or try using the xmms-alarm and xmms-goodnight. They're available from Dag's RPM repository.

woedend
11th July 2005, 04:25 AM
i'm very new to linux but learning as I go...i'm not computer illiterate by any means, just...linux illiterate for now. I've picked up basic commands such as using su, yum, and mounting devices in console and fstab...and well thats about it! I don't mind editing services in command mode if that's what it takes. I don't know how to use/get cronjobs or even what that is. I was just using KCron which I assume is barely better than useless since it has never launched anything? xmms alarm I tried but cannot figure out how to shut it down, it doesn't actually show me a window? I need to launch two different instances of xmms or amarok for that matter at two different times and if you guys could point me in the right direction or give me detailed instructions i'd be grateful. Thank you,
Alex

BandC
11th July 2005, 05:25 PM
Since you can't run X programs from task scheduler, would playing your songs with mpg321 (a command line program) work?

crackers
12th July 2005, 04:16 AM
Yup. And, woedend, yes, using KCron is correct. Each "timed task" in the file you edit is quaintly termed a "cronjob" because the cron scheduler (which is installed and running by default) reads these files and executes the tasks at the specified times. For local reference, you can read about cron and crontab via the GUI help systems ("man pages").

woedend
13th July 2005, 09:10 AM
i still wish it would actually launch a windowed application. My temporary workaround is to leave xmms running and use the same command, in which it does start playing it. However if it is shut it will not launch it...any way to make that happen?

xyleo
17th November 2005, 11:21 AM
currently i have add this line into my /etc/crontab file

1 * * * * env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/cfg/mrtg19.cfg

1 * * * * env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/cfg/mrtg20.cfg



I want this command to run in my terminal for every 1 minutes. Did i did the right way of specifying my cronjob. When i check my mrtg graph, i can't still able to view my latest graph up to date which it means my cronjob is not functioning. can anyone help me. ur help is greatly appreciated.

many many thanx a million
cheers
"xyleo"

mbokil
3rd January 2006, 12:45 AM
I wrote a python script that will play a media player such as xmms when an alarm goes off. Easier to setup than cron if you are having problems. Just execute the script from a shell and let it run. When it goes off it increases the volume to your setting and runs a script. It is nice to have some mp3's playing to wake you up. Edit the cmd variable to point to your executable. Save this file as alarm.py and then execute it by entering 'python alarm.py' from a shell.


#!/usr/bin/python
# alarm script

import time
import os
import ossaudiodev

delayTime = 60.0 # Seconds
alarmM = 0 # Alarm minute
alarmH = 7 # Alarm Hour military format
volume = 56 #set volume for alarm
cmd = "/home/mbokil/bin/alarm" #command to run
# inside the alarm script is /usr/bin/xmms ~/playlists/favorites.m3u
mixer = ossaudiodev.openmixer()

def main():
hour = time.localtime()[3]
minute = time.localtime()[4]

os.system('clear')

if hour == alarmH and minute == alarmM:
print "Alarm!"
mixer.set(ossaudiodev.SOUND_MIXER_VOLUME, (volume,volume))
os.system(cmd)

if hour > 12 : hour = hour - 12
if hour == 0 : hour = 12
if minute <= 9 : minute = "0" + str(minute)

print str(hour) + ":" + str(minute)
time.sleep(delayTime)

while 1:
main()

w5set
3rd January 2006, 01:21 AM
tryied KAlarm yet?
if installed it's under accessories (KDE)

mbokil
3rd January 2006, 02:21 AM
I don't have it installed but writing your own script is much more fun and only requires a shell or terminal.

wdingus
3rd January 2006, 03:31 AM
The "task scheduler" in Unix/Linux is cron as has been mentioned. What's quite a bit different with it and it's Windows counterpart has to do with the underlying system. Unix/Linux is multi-user, so multiple login sessions and hence multiple "desktops" might exist. Launching xmms from cron doesn't mean it automatically knows which desktop to attach to. This is easily remedied by setting the DISPLAY variable though. I'm logged on locally with my own user account and created /tmp/wakeup.sh just now with the following contents:

#!/bin/bash
export DISPLAY=:0.0
/usr/bin/xmms /tmp/song.ogg

I then added it to my crontab file as such:

29 21 * * * /tmp/wakeup.sh

Which should run it every single day of every week and every month at 9:29PM Anyway, I paused a couple of minutes and xmms fired up on my desktop and started playing. It knew which graphical desktop session to attach to because of the DISPLAY variable being set. If you're the only user logging in graphically, yours will also most likely be 0.0

For the other person who mentioned /etc/crontab, that's more of a "system" crontab file. The root user can also have one as well as whatever local user you login as. Edit the files with "crontab -e" logged in as the user for which you want to edit it. Afterwards restart cron daemon with "service crond restart" or do so pointy-clicky Desktop->Server Settings->Services. Also note I created a small script file and set teh environment variable in there instead of attempting to do so all in the command portion of the crontab entry. That's quite possible, it's just easier and more flexible in a small script.

Don't forget to "chmod a+x wakeup.sh" to make this file executable else it will not run...

mbokil
3rd January 2006, 06:32 AM
cron is useful if you have the permissions but it often doesn't work unless it is setup right. For example the above crontab will only work unless the user has been added to crontab or it will generate an error. Also SE Linux can mess it up preventing scripts from running. It is good for system stuff running at root on automatic schedules but lately with Fedora 4 I have been having bad luck with it with limited user accounts. I just find it easier to run a threaded Python script in the background and avoid the whole permission problem. That is the great thing about linux there are many ways to do the same thing depending on how you want to set it up.

wdingus
3rd January 2006, 01:15 PM
Interesting.. I manage a lot of FC, RH, and RHEL servers all running probably 15+ scheduled systems maintenance and similar things via cron without issue. I had never stopped to think about permissions for cron, never had an issue with it. I just did a bit of quick reading and see there's a cron.allow and cron.deny file which can either give or take this permission but on my FC4 box neither exist by default. If you're having problems with firing things off in cron I find it's usually helpful to add a 1> and 2> to some file in /tmp on the end of the cron command line. If it fails to fire off what you wanted it to, check these files for any helpful tidbits.

SELinux could definitely be a problem, it's thwarted me in other areas before. I just took a look through it's config though and didn't find any references to cron. Again though, this is FC4, some other distro might have cron managed by it.

Something interesting to note, the cron daemon "anacron in my case, could be vixie or something else for you" also takes care of firing things off started with "at". I love the time parser in "at"...

$ at 7pm tomorrow
at> do something
at> <EOT>
job 6 at 2006-01-04 19:00

$ at 8pm next week
at> do something else
at> followed by something else
at> <EOT>
job 7 at 2006-01-10 20:00

mbokil
4th January 2006, 04:44 PM
Hey that 'at' command is pretty useful. I hadn't know about it. Unix is pretty amazing sometimes. The amount of options to do the same thing is staggering. I recently disabled SE Linux to see if it would help cron work better on FC4 and it still had no effect. I ended up adding my account to the allow file and now it works. I figured out what was going on by looking in the cron log file and it kept repeating an error about missing a password. Possibly with a limited user account this is disabled by default.