Can I trigger a media scan via the command line? Is it possible to trigger the media scanner to update its DB via the command line?

I have an SSH server installed on my Android device and I copy files to/from over the same link. It would be great if I could also trigger a re-scan for the media scanner.

I am aware that there are applications on the market to do this via the UI but this is not what I want.

Any help fully appreciated.
The SSH server doesn't set all the necessary environment variables so it is easier to use a shell script.

#!/system/bin/sh

export ANDROID_ASSETS=/system/app
export ANDROID_CACHE=/cache
export ANDROID_DATA=/data
export ASEC_MOUNTPOINT=/mnt/asec
export ANDROID_ROOT=/system
export BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar
export EXTERNAL_STORAGE=/mnt/sdcard
export LD_LIBRARY_PATH=/vendor/lib:/system/lib

am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///mnt/sdcard


When successful:

# rescan-media
Broadcasting: Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///mnt/sdcard }
Broadcast completed: result=0


This works on Cyanogenmod 9.1. Depending on your system the environment may be slightly different.

Note: In later versions of Cyanogenmod / Android the SD card may be mounted at /storage/sdcard0. Make sure you know where your card is mounted or this will never work. Diskinfo may help here.

Thanks to Dan Hulme for pushing me in the right direction.

References:

http://developer.android.com/reference/android/content/Intent.html
http://forum.xda-developers.com/showthread.php?t=1752749
http://intwoplacesatonce.com/
http://kennystechtalk.blogspot.co.uk/2013/08/start-android-media-scanner-from.html