Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:35:40+00:00 2026-06-12T01:35:40+00:00

I’m new to linux and I’m learning to script an alarm clock using bash

  • 0

I’m new to linux and I’m learning to script an alarm clock using bash and cron. The script works fine from bash and by double clicking on it, but not from cron; as soon as cron calls the script, the alarm sounds once (one loop, it seems) and then stops without even showing the dialog box (zenity). I’m using Linux Mint 13 Maya XFCE.

Here is my crontab setup

* * * * * /home/x/Documents/MyScripts/Cron/BeepAlarm "Wake Up"

And here is my script

!#/bin/bash

# Initialize Variables
Text=$1
Title="Alarm"
OkLabel="Snooze"
CancelLabel='Shut It Up!'
Icon=/home/x/.icons/actions/48/appointment-new.png # Won't work
SnoozeTimeout=120
AlarmCycles=100
shopt expand_aliases
alias vol='amixer -q -c 0 sset Beep'
vol 25% # Heart friendly
rm -f LoopMode # Just in case =P

# Dialog Box Function
_MsgBox () {
    if zenity --question --title="$Title" \
    --window-icon=$Icon --ok-label="$OkLabel" \
    --cancel-label="$CancelLabel" --text="$Text"
    then
        echo 1 > LoopMode
    else
        echo 2 > LoopMode
        #kill -TERM `jobs -p` # Won't work
    fi
}

# Alarm Loop
while [ $AlarmCycles -gt 0 ]; do
    case `cat LoopMode` in
        "") # Question Box
            echo 0 > LoopMode
            _MsgBox &
            ;;

        1)  # Snooze
            vol 25%
            rm -f LoopMode
            sleep $SnoozeTimeout
            ;;

        2)  # Stop Alarm
            break # But don't sleep again
            ;;

        *)  # Get on my nerves
            beep -r 4 -l 20 -f 2000; sleep 0.5
            beep -r 4 -l 20 -f 4000; sleep 0.5
            AlarmCycles=$((AlarmCycles-1))
            vol 5%+

    esac
done

# Housekeeping~
kill $(($!+2)) # I don't know a better way to kill zenity Dialog
vol 25%   #  =)
rm -f LoopMode
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:35:41+00:00Added an answer on June 12, 2026 at 1:35 am

    As Rob suggested:

    * * * * * env DISPLAY=:0.0 /home/x/Documents/MyScripts/Cron/BeepAlarm "Wake Up"
    

    P.S: Sorry, I didn’t pay attention to the formalities

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.