3

I'm writing a couple of scripts to start vlc and periodically update its playlist. The update_pls.sh works well if I execute it from prompt, but when I call it from start_vlc.sh, in each for cycle I get this:

./update_pls.sh: 20: ./update_pls.sh: 10#18: not found
./update_pls.sh: 20: ./update_pls.sh: 10#18==DIA: not found

start_vlc.sh:

   #!/bin/bash
   echo `date`
   echo "A arrancar o VLC..."
   cvlc --loop --fullscreen --extraintfttp --http-password kepler
   sh update_pls.sh

update_pls.sh:

   #!/bin/bash
   /usr/bin/env > /Videos/cron_env.log
   DIR=/Videos
   FILES=$DIR/*
   DIA=`(date +%d)`
   HORA=`(date +%H)`
   echo `date`
   echo "Dir: $DIR"
   echo "A fazer update da playlist.m3u..."
   > $DIR/playlist.m3u
   for f in $FILES
   do
     a=`(basename $f .mov | cut -b 1-2 | sed 's/[^0-9]//g')`
     b=`(basename $f .mov | cut -b 3-4 | sed 's/[^0-9]//g')`
     if [ -n "$a" ]; then    
       :
     else
       a="99"
     fi
     if (( 10#$a<DIA)) || ((10#$a==DIA && 10#$b<=HORA )); then
       echo -e "$f\n" >> $DIR/playlist.m3u
       echo "Adicionado o video $f"
     fi
   done
   echo "A fazer upload da playlist para o VLC..."
   curl -u '':kepler "http://localhost:8080/requests/status.xml?command=pl_empty"
   curl -u '':kepler "http://localhost:8080/requests/status.xml?command=in_enqueue&input$
   curl -u '':kepler "http://localhost:8080/requests/status.xml?command=pl_play"

I can't manage to find the cause of this and would apreciate any help. Vasco

countermode
  • 7,533
  • 5
  • 31
  • 58

1 Answers1

2

Your update_pls.sh is a bash script, but when you invoke it from start_vlc.sh you use sh which probably doesn't run bash on your system. Try either changing the line to bash update_pls.sh or do chmod a+x on update_pls.sh and just invoke it directly as a command.

A few notes on your scripts:

In the line echo `date`, echo is unnecessary, just use date.

No need for parenthesis in lines like DIA=`(date +%d)`, including these will start another instance of your shell and add a lot of overhead to the script. DIA=$(date) is probably the most preferable form (here the dollar brackets replace the backticks), see Have backticks (i.e. `cmd`) in *sh shells been deprecated?.

No need for a : in your if/else, just do if ! [ -n "$a" ]; then and you can drop the else part.

There are some other things, but I think that is enough from me.

Graeme
  • 34,027
  • 2
    @mikeserv On my Debian system /bin/sh is a symlink to dash. – Dubu Aug 21 '14 at 22:23
  • @Dubu - thats true. Id forgotten that. dash is a better shell than bash's --posix mode anyway, as it too often confuses itself, i think. And it will be that way on all Debian based systems - which completely invalidates my comment. Sorry, Graeme. In all, though, i would recommend vlc -I lua - which invokes vlc's own scriptable cli - over all of this. – mikeserv Aug 21 '14 at 22:25