32

How can I remotely (SSH) make my Linux Computer Beep (built-in speaker, as there are no external ones)? I have ubuntu 9.04 and can install extra packages if need be. This would be good for finding a certain box if you have more than one standing around and forgot which IP is which box.

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
wsd
  • 493

9 Answers9

28

Try:

sudo sh -c "echo -e '\a' > /dev/console"

You may have to load the kernel module for the built-in speaker first (e.g. if the module was blacklisted from auto-loading):

sudo modprobe pcspkr
wsd
  • 493
14

first:

modprobe pcspkr

then solutions from topic, like

ssh user@host
beep
maizy
  • 140
7

From the beep man page on my Ubuntu machine:

IOCTL WACKINESS

Some users will encounter a situation where beep dies with a complaint from ioctl(). The reason for this, as Peter Tirsek was nice enough to point out to me, stems from how the kernel handles beep’s attempt to poke at (for non-programmers: ioctl is a sort of catch-all function that lets you poke at things that have no other predefined poking-at mechanism) the tty, which is how it beeps. The short story is, the kernel checks that either:

  • you are the superuser

  • you own the current tty

What this means is that root can always make beep work (to the best of my knowledge!), and that any local user can make beep work, BUT a non-root remote user cannot use beep in it’s natural state.

This could well be the reason why beep refuses to work remotely. You can check if this is the root cause by invoking ssh with the -t option, which forces pseudo-tty allocation.

A less desirable solution would be to create a wrapper script that executes beep, and grant this script root permissions. If executing this script over ssh duly produces a beep, you'll know that the issue is the lack of a controlling terminal.

3

This command will do the trick:

modprobe pcspkr; echo -e "\a" > /dev/console;
jokerdino
  • 2,465
Sayajin
  • 31
3

You can use:

ssh user@remote-machine
sudo sh -c "echo -e '\a' > /dev/tty1"


Note that the following would not work. It fails before even prompting for the sudo password because the (bash) shell is doing the redirection, and that shell still runs as the normal user, not as root:

ssh user@remote-machine
sudo echo -e '\a' > /dev/tty1
-bash: /dev/tty1: Permission denied
ls -la /dev/tty1
crw------- 1 root root 4, 1 2009-09-28 16:33 /dev/tty1
Arjan
  • 31,511
Thomas
  • 619
3

Just type

ssh user@remote-machine
beep

Tested on Ubuntu Desktop 8.x, this will beep on the remote server, even if no local session on that server is active (thus: even if the GNOME login screen is shown on the monitor attached to the server).

Have a look at

man beep

for more details. On Debian/Ubuntu, the beep package has to be installed and the speakers must not be muted.

Arjan
  • 31,511
Kim
  • 2,418
0

This all works perfect after logging in and opening a tty device. When for instance you want a beep from rc.local to know when your linux machine is ready booting, like a intel nuc, run this script /root/bin/boot-complete.sh from /etc/rc.d/rc.local :

#!/bin/sh
# this is /root/bin/boot-complete.sh

/sbin/modprobe pcspkr
/bin/sleep 1
/usr/bin/aumix -p 75
echo -e '\a' > /dev/tty1 2>&1
/bin/sleep 1
echo -e '\a' > /dev/tty1 2>&1

exit 0
0

Run a remote command to the remote machine:

rsh hostname /usr/bin/echo '\a'
or
ssh user@remotehost /usr/bin/echo '\a'

harrymc
  • 498,455
0

Or, you could simply run the following once:

chmod o+x `which beep`

This will allow all users to use the beep executable, which probably is safe enough in most cases.

Arjan
  • 31,511