Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'

share|improve this question
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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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