在Ubuntu下用crontab定制mplayer提醒


   Ubuntu 8.04。crontab 是 Linux 下面定时运行程序的工具。编辑下面一个shell脚本mp3.sh:

  #! /bin/sh

  mplayer /home/administrator/Others/mp3/lanlianhua.mp3

  通过chmod u+x给予可执行属性。则可以在命令行通过./mp3.sh播放歌曲。然而,如果通过crontab -e编辑定时文件

  15 * * * * /home/administrator/mp3.sh

  也就是说,在每个小时的第15分钟播放歌曲,却不行。

  后来,在论坛上到处找,都说需要给gui程序设置显示设备:例如

  realplay export DISPLAY=:0 /home/administrator/Others/mp3/lanlianhua.mp3

  我测试了一下,确实是那么回事。不过,realplay可以,mplayer还是不行。

  最终是这么解决的:mplayer /home/administrator/Others/mp3/lanlianhua.mp3 >/dev/null

  我是知其然,不知其所以然。难道?这样做是不给mplayer分配控制台?

  不管怎么说,问题是解决了。

相关内容