0

I'm currently writing a simple bash script for recording a streaming radio stream. The logistics of getting into work and getting set up mean that I miss about 30 minutes of my favourite breakfast show, so I'm writing this script with the intention of putting it on a cron schedule on my work machine to start recording about 15 minutes before I get to work.

The following excerpt from the script does not work:

echo ${FILEFULLPATH} | xargs -t screen -dmS ${STATION_NAME}Stream mplayer ${STATION_URL} -dumpstream -dumpfile

However, running the xargs -t output works perfectly - screen -ls shows the screen and screen -r shows that the command is indeed running. This is that output command:

screen -dmS RadioXStream mplayer http://radiostream.net/ -dumpstream -dumpfile ~/radio/radiostream_06102015-1316.mp3

I've used set -x and everything looks fine. When I run screen -ls after running the script, the screen that is supposed to have created does not exist.

I based this command on an earlier script I wrote for a Minecraft server, with the only main difference being that I use xargs here for the filepath, as it was wrapping a relative directory in quotes, e.g '~/radio/file.mp3'

  • 2
    I think you're overcomplicating your script by using xargs and screen. Why not simply have cron run mplayer http://radiostream.net/ -dumpstream -dumpfile ~/radio/radiostream_06102015-1316.mp3? – Anthony Geoghegan Oct 6 '15 at 13:01
  • ... with radiostream_06102015-1316.mp3 generate by $(date "+radiostream_%d%m%Y_%H%M.mp3") in command line – Archemar Oct 6 '15 at 13:12
  • Because I do this: FILEFULLPATH="${DIRECTORY}${STATION_NAME}_${DATETAG}.mp3" – Jake Stanley Oct 6 '15 at 14:29
0

The problem must have been caused by using xargs. I solved my problem by sticking all the variables on the command line instead of putting them in a variable:

screen -dmS ${STATION_NAME}Stream mplayer ${STATION_URL} -dumpstream -dumpfile ${DIRECTORY}${STATION_NAME}_${DATETAG}.mp3

Thanks for the comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.