The answer is
xdotool, and it might already be installed on your Ubuntu system. It can simulate keypresses. See also .
xdotool key XF86AudioPlay
xdotool key XF86AudioPrev
xdotool key XF86AudioNext
xdotool key XF86AudioLowerVolume
xdotool key XF86AudioRaiseVolume
xdotool key XF86AudioMute
For more XF86 commands see .
Instead of doing the volume step by step you can also set it using alsamixer or pulseaudio (recommended). Assuming you use device 0 (you can check this with
pacmd list-sinks) you can set the volume to for instance 80% with
alsamixer (-c 0 specifies the sound device id)
amixer -c 0 sset Master,0 80%
pulseaudio (the 0 in front of the 80% is the sound device id)
pactl set-sink-volume 0 80%
For more information about these commands see their manpages.
If you're trying to do the xdotool commands over ssh and get the following error message
Error: Can't open display: (null)
you need to set the DISPLAY variable:
After that it should work without problems