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

8
  • When you are calling the script, can you put in the directory the script is located in? For example .~/directory/scriptName.sh Commented Aug 21, 2014 at 18:05
  • both scripts, and files it's supposed to add to the playlist, are in the same folder, p.e. /home/vasco/videos/. Commented Aug 21, 2014 at 18:08
  • Ok next dumb question lol: is the script listed as an executable? Commented Aug 21, 2014 at 18:09
  • 1
    @VascoSotomaior in UNIX world, you have to specify path for executing script or run from $PATH. Commented Aug 21, 2014 at 18:11
  • yup, after writing them i ran sudo chmod +x *.sh Commented Aug 21, 2014 at 18:11

1 Answer 1

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.

2
  • 2
    @mikeserv On my Debian system /bin/sh is a symlink to dash. Commented Aug 21, 2014 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. Commented Aug 21, 2014 at 22:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.