LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 01-29-2012, 06:21 AM   #1
stephaneeybert
Member
 
Registered: Feb 2005
Posts: 32

Rep: Reputation: 9
Bell sound alert on bash shell giving me the prompt


Hello,

I'm a user of bash and I'd like to set it up so that it rings the bell every time a command terminates, successfully or not, and hands me the prompt again.

This would wake me up :-) And I would not have to stare at the screen, ruining my eyes.

Think of all of us who could then close their eye lids for some 3 to 30 seconds, rest their eye sight and brain...

Any way this very usefull little utility can be done ?

Kind Regards,

Stephane
 
Old 01-29-2012, 07:25 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,388
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Just set the command prompt to have a bell in it ('\a' or '\007'), for example:
Code:
PS1='\u@\h:\w\$\a '
You can set this in a local profile file, eg .bash_profile or similar.

Last edited by neonsignal; 01-29-2012 at 07:26 AM.
 
Old 01-29-2012, 07:52 AM   #3
stephaneeybert
Member
 
Registered: Feb 2005
Posts: 32

Original Poster
Rep: Reputation: 9
I did this:

stephane@stephane-ThinkPad-X60:~> PS1='\u@\h:\w\$\a '
stephane@stephane-ThinkPad-X60:~$ sleep 6
stephane@stephane-ThinkPad-X60:~$

But it did not beep after the sleep command was done.

I'd like to have a beep after the shell hands me the prompt over. On any commands.
 
Old 01-29-2012, 08:13 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,388
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Does the following bash command beep?
Code:
printf '\a'
If not, the system bell might be disabled. You could check the volume controls, and also try the following:
Code:
xset b 50
printf '\a'
If the system bell is working, even just pressing backspace at the shell prompt should elicit a beep.

Last edited by neonsignal; 01-29-2012 at 08:15 AM.
 
Old 01-29-2012, 08:30 AM   #5
stephaneeybert
Member
 
Registered: Feb 2005
Posts: 32

Original Poster
Rep: Reputation: 9
The command:

printf '\a'

does ring the bell and I hear it every time.

But if I type in the command:

sleep 3

and then wait, I never hear the bell after the command is done and I get the prompt again.

Having a bell ring every time any command terminates would allow me to do something else, instead of waiting for the command to terminate.
 
Old 01-29-2012, 10:29 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
This might work
Code:
PROMPT_COMMAND="printf '\a'"
 
Old 01-29-2012, 12:27 PM   #7
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
Ring the bell

Here is a link to ringing the terminal bell in just about every computer language - not useful but interesting.
http://rosettacode.org/wiki/Terminal..._terminal_bell

other wise try this:

'very long process' && echo -e "\a"

should ring the bell, however the caveat is that the bell must be enabled and if it is not all you will see is a blank newline and then your prompt.

Test it beforehand:

your prompt % echo -e "\a" and smash enter

If all you get is a space the bell is disabled, non-existent or broken. I am certain you could figure out some other way to alert yourself when a process has finished using a script. This is for you to discover.

There are more than a million hits on any search engine resolving the bell ringing issue.

Bon chance mon ami.
 
Old 01-29-2012, 12:31 PM   #8
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
An alternative would be to use a process that sends a message to every terminal and interrupts what you are doing there. Perhaps you should try a script to schedule these long processes and forget them until later, that is what computers are really good at, doing stuff by themselves.
 
Old 01-29-2012, 03:34 PM   #9
stephaneeybert
Member
 
Registered: Feb 2005
Posts: 32

Original Poster
Rep: Reputation: 9
Thanks all for your comments !

This one worked good

PROMPT_COMMAND="printf '\a'"

but it rings the bell on every return key strike :-)

I guess for now I'll put this aside and try to come up with a solution that would ring the bell only when scripts taking more than 3 seconds terminate.

That'd be nice.

Last edited by stephaneeybert; 01-29-2012 at 03:40 PM.
 
Old 01-30-2012, 02:32 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Then you could run them via a front end script, something like
Code:
#!/bin/bash

start_time=$( date '+%s' )
"$@"
rc=$?
end_time=$( date '+%s' )
(( (end_time - start_time) > 3 )) && printf '\a'
exit $rc
 
Old 01-30-2012, 03:18 AM   #11
stephaneeybert
Member
 
Registered: Feb 2005
Posts: 32

Original Poster
Rep: Reputation: 9
Thanks ! I shall try it asap..
 
Old 09-01-2015, 04:58 AM   #12
motoservo
LQ Newbie
 
Registered: Sep 2015
Posts: 1

Rep: Reputation: Disabled
Answer

This is an old thread but just stumbled on it while looking up the meta for a system sound. I've answered here for whoever else needs to know and finds this page.

Chain the echo command whenever you want the alert (with a command you think might last awhile):

Code:
$sleep 4; echo -e "\007"
That way, the sound command doesn't start until the previous finishes.

You can also shorten the echo part to just a z (for sleep) with an alias by adding something like this to your .bash_profile

Code:
alias z='echo -e "\007"
Code:
sleep 4; z
Hope this helps.

Troy Dalmasso

Last edited by motoservo; 09-01-2015 at 05:11 AM.
 
  


Reply


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
bash shell prompt show incorrect hostname. hari85 Linux - Newbie 3 06-22-2010 04:10 AM
passing parameters from a unix shell prompt into a windows cmd.exe prompt nano2 Programming 1 09-01-2009 11:26 AM
changing the BASH shell prompt 24jedi *BSD 12 03-01-2005 03:11 AM
alert bell character in asp pragti Programming 0 06-11-2004 02:55 AM
Cygwin:How do you turn the bash shell bell off? petercool Linux - Newbie 8 05-23-2003 10:48 AM


All times are GMT -5. The time now is 10:29 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration