1BEEP(1) General Commands Manual BEEP(1)
2
3
4
6 beep - beep the pc speaker any number of ways
7
9 beep [-f N] [-l N] [-r N] [-d N] [-D N] [-s] [-c]
10
11 beep [ OPTIONS ] [-n] [--new] [ OPTIONS ]
12
13 beep [-h] [--help]
14
15 beep [-v] [-V] [--version]
16
18 beep allows the user to control the pc-speaker with precision, allowing
19 different sounds to indicate different events. While it can be run
20 quite happily on the command line, it's intended place of residence is
21 within shell/perl scripts, notifying the user when something interest‐
22 ing occurs. Of course, it has no notion of what's interesting, but
23 it's real good at that notifying part.
24
25 All options have default values, meaning that just typing 'beep' will
26 work. If an option is specified more than once on the command line,
27 subsequent options override their predecessors. So 'beep -f 200 -f
28 300' will beep at 300Hz.
29
31 -f N beep at N Hz, where 0 < N < 20000. As a general ballpark, the
32 regular terminal beep is around 750Hz. N is not, incidentally,
33 restricted to whole numbers.
34
35 -l N beep for N milliseconds.
36
37 -r N specify the number of repetitions (defaults to 1).
38
39 -d N, -D N
40 specify a delay of N milliseconds between repetitions. Use of
41 -d specifies that this delay should only occur between beeps,
42 that is, it should not occur after the last repetition. -D
43 indicates that the delay should occur after every repetition,
44 including the last. Normally, -d is what you want, but if, for
45 example, you are stringing several beep commands together to
46 play the star wars anthem, you may want control over every
47 delay.
48
49 -n, --new
50 this option allows you to break the command line up into speci‐
51 fying multiple beeps. Each time this option is used, beep
52 starts treating all further arguments as though they were for a
53 new beep. So for example:
54
55 beep -f 1000 -n -f 2000 -n -f 1500
56
57 would produce a sequence of three beeps, the first with a fre‐
58 quency of 1000Hz (and otherwise default values), then a second
59 beep with a frequency of 2000Hz (again, with things like delay
60 and reps being set to their defaults), then a third beep, at
61 1500Hz. This is different from specifying a -r value, since -r
62 repeats the same beep multiple times, whereas -n allows you to
63 specify different beeps. After a -n, the new beep is created
64 with all the default values, and any of these can be specified
65 without altering values for preceeding (or later) beeps. See
66 the EXAMPLES section if this managed to confuse you.
67
68 -s, -c these options put beep into input-processing mode. -s tells
69 beep to read from stdin, and beep after each newline, and -c
70 tells it to do so after every character. In both cases, the
71 program will also echo the input back out to stdout, which makes
72 it easy to slip beep into a text-processing pipeline, see the
73 EXAMPLES section.
74
75 -h, --help
76 display usage info and exit
77
78 -v, -V, --version
79 display version information and exit
80
82 At its simplest (yet still effective)
83
84 beep
85
86 A more interesting standalone setup
87
88 beep -f 300.7 -r 2 -d 100 -l 400
89
90 As part of a log-watching pipeline
91
92 tail -f /var/log/xferlog | grep 'passwd' | beep -f 1000 -r 5 -s
93
94 When using -c mode, I recommend using a short -D, and a shorter -l, so
95 that the beeps don't blur together. Something like this will get you a
96 cheesy 1970's style beep-as-you-type-each-letter effect
97
98 cat file | beep -c -f 400 -D 50 -l 10
99
100
101 A highly contrived example of -n/--new usage
102
103 beep -f 1000 -r 2 -n -r 5 -l 10 --new
104
105 will produce first two 1000Hz beeps, then 5 beeps at the default
106 tone, but only 10ms long each, followed by a third beep using
107 all the default settings (since none are specified).
108
110 Some users will encounter a situation where beep dies with a complaint
111 from ioctl(). The reason for this, as Peter Tirsek was nice enough to
112 point out to me, stems from how the kernel handles beep's attempt to
113 poke at (for non-programmers: ioctl is a sort of catch-all function
114 that lets you poke at things that have no other predefined poking-at
115 mechanism) the tty, which is how it beeps. The short story is, the
116 kernel checks that either:
117
118 - you are the superuser
119
120 - you own the current tty
121
122 What this means is that root can always make beep work (to the best of
123 my knowledge!), and that any local user can make beep work, BUT a non-
124 root remote user cannot use beep in it's natural state. What's worse,
125 an xterm, or other x-session counts, as far as the kernel is concerned,
126 as 'remote', so beep won't work from a non-priviledged xterm either. I
127 had originally chalked this up to a bug, but there's actually nothing I
128 can do about it, and it really is a Good Thing that the kernel does
129 things this way. There is also a solution.
130
131 By default beep is not installed with the suid bit set, because that
132 would just be zany. On the other hand, if you do make it suid root,
133 all your problems with beep bailing on ioctl calls will magically van‐
134 ish, which is pleasant, and the only reason not to is that any suid
135 program is a potential security hole. Conveniently, beep is very
136 short, so auditing it is pretty straightforward.
137
138 Decide for yourself, of course, but it looks safe to me - there's only
139 one buffer and fgets doesn't let it overflow, there's only one file
140 opening, and while there is a potential race condition there, it's with
141 /dev/console. If someone can exploit this race by replacing /dev/con‐
142 sole, you've got bigger problems. :)
143
144 So the quick, only, and likely safe solution if beep is not beeping
145 when you want it to is (as root):
146
147 # chmod 4755 /usr/bin/beep
148
149 (or wherever you put it)
150
151 The one snag is that this will give any little nitwit the ability to
152 run beep successfully - make sure this is what you want. If it isn't,
153 a slightly more complex fix would be something like:
154
155 # chgrp beep /usr/bin/beep
156
157 # chmod 4750 /usr/bin/beep
158
159
160 and then add only beep-worthy users to the 'beep' group.
161
163 Several people have asked for some basic help translating music notes
164 to frequencies. There are a lot of music notes, and several tables
165 online will give you translations, but here are approximate numbers for
166 the octave of middle C, to get you started.
167
168 Note Frequency
169 C 261.6
170 C# 277.2
171 D 293.7
172 D# 311.1
173 E 329.6
174 F 349.2
175 F# 370.0
176 G 392.0
177 G# 415.3
178 A 440.0
179 A# 466.2
180 B 493.9
181 C 523.2
182
184 None that I'm aware of, though see the IOCTL WACKINESS section.
185
187 Report bugs to <johnath@johnath.com>
188
190 This program was written by Johnathan Nightingale (johnath@johnath.com)
191 and is distributed under the GNU General Public License. For more con‐
192 tributing information, check the source, and past contributors can be
193 found in CREDITS.
194
195
196
197
198
199
200
201
202
203
204 March 2002 BEEP(1)