Results 1 to 5 of 5

Thread: Alarmin crontab

  1. #1
    Join Date
    Aug 2006
    Beans
    445

    Alarmin crontab

    I would like to have some audio alarms initiated in crontab.

    I was under the impression that any legit CLI command could be used in a crontab file.

    Code:
    play whatever.wav
    works just fine on CLI ... but I am unable to get it to perform in crontab.

    Should I be able to?

    If yes, then what might I be missing in getting it to work?

    If no, then can someone suggest another way I can get working alarms?

    Thanks in advance.

  2. #2
    Join Date
    Aug 2016
    Location
    Wandering
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: Alarmin crontab

    Not sure if you have seen this yet: https://help.ubuntu.com/community/CronHowto
    More info here: https://askubuntu.com/questions/7195...o-play-a-sound
    "gnome-schedule" can add a simple to use solution.
    With realization of one's own potential and self-confidence in one's ability, one can build a better world.
    Dalai Lama>>
    Code Tags | System-info | Forum Guide lines | Arch Linux, Debian Unstable, FreeBSD

  3. #3
    Join Date
    Aug 2006
    Beans
    445

    Re: Alarmin crontab

    Thanks for taking the time to respond.

    Maybe it's just my pea brain but I don't see how the url's you cited apply.

    My crontab has perhaps a hundred lines ... all of which work fine. So crontab syntax is not an issue.

    I'm afraid I don't see the applicability of the "play-a-sound" url to my "play/crontab" issue.

    Unless you ARE saying that "play" does NOT work in crontab and that I should instead run a script from crontab ...

    So I'm back to the question "should play work in crontab"? And, if so what might/could be wrong?

    Again thanks.

  4. #4
    Join Date
    Aug 2016
    Location
    Wandering
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: Alarmin crontab

    Play needs more: (Nor have I used the term "play" in any cron jobs)
    Cron passes a minimal set of environment variables to your jobs.
    A common "gotcha" here is the PATH environment variable being different. Maybe your cron script uses the command somecommand found in /opt/someApp/bin, which you've added to PATH in /etc/environment? cron ignores PATH from that file, so runnning somecommand from your script will fail when run with cron, but work when run in a terminal. It's worth noting that variables from /etc/environment will be passed on to cron jobs, just not the variables cron specifically sets itself, such as PATH.

    To get around that, just set your own PATH variable at the top of the script. E.g.
    Code:
    #!/bin/bash
    PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    
    # rest of script follows
    Some prefer to just use absolute paths to all the commands instead. I recommend against that.
    Perhaps if you showed us the script your trying to use it would help us to help you.
    Example of just one of my crontab -e......For just giving me the time every hour.
    Code:
    #!/usr/bin/env bash
    my_date=$(date +'%I:%M:%S')
    padsp espeak "$my_date"
    My "crontab -e"reads as follows:
    Code:
    0 * * * * bin/say_hour
    Enter the time (multiple times, days need to be separated with commas) and the script to execute for the alarm. The asterik can be used (*) to satisfy all variables. example for audacious:
    Code:
    07  21  *   *   1,2,3,4,5   env DISPLAY=:0.0 audacious /home/user/My\ Music/Other/Alarms/301gq.mp3
    Last edited by 1fallen; February 21st, 2019 at 08:24 PM. Reason: added to code
    With realization of one's own potential and self-confidence in one's ability, one can build a better world.
    Dalai Lama>>
    Code Tags | System-info | Forum Guide lines | Arch Linux, Debian Unstable, FreeBSD

  5. #5
    Join Date
    Aug 2006
    Beans
    445

    Re: Alarmin crontab

    Thanks for your very complete response which has resulted in me now having a working alarm.

    I appreciate your help.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •