Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Problem with shell script

  1. #1
    Join Date
    Feb 2013
    Beans
    5

    Problem with shell script

    hello guys.

    I have a problem in a shell script, already tried the solution here in the forum, but to no avail so far.

    ps.: I have the same script on 2 machines, one works, the other does not.

    -------------------- SCRIPT --------------
    #!/bin/bash
    MES=`date +%m`
    ANO=`date +%Y`
    if [ $MES -eq 12 ]; then
    ANO_PASTA=$(($ANO+1))
    MES_ARQUIVO=01
    else
    ANO_PASTA=$ANO
    MES_ARQUIVO=$(($MES+1))
    fi
    PASTA_TEMP=/var/www/tgnet/boletos/$ANO_PASTA/temp
    PASTA_SEG=/var/www/tgnet/boletos/$ANO_PASTA/segunda-via
    PASTA=/var/www/tgnet/boletos/$ANO_PASTA/
    ARQUIVO=$PASTA$MES_ARQUIVO.pdf
    GRUPO_A_CONVERTER=""
    mkdir -p $PASTA
    chmod 0777 $PASTA
    mkdir -p $PASTA_TEMP
    chmod 0777 $PASTA_TEMP
    mkdir -p $PASTA_SEG
    chmod 0777 $PASTA_SEG
    cd $PASTA_TEMP
    curl -s -u tgnetSys:senhaDoSys http://localhost:7979/eng/gera_boleto.php
    for PDF in *.pdf;
    do
    GRUPO_A_CONVERTER=$GRUPO_A_CONVERTER' '$PDF
    done
    pdftk $GRUPO_A_CONVERTER cat output $ARQUIVO
    for PDF2 in *.pdf;
    do
    rm $PDF2
    done
    rmdir $PASTA_TEMP


    ------- ERROR -------------
    gera_boleto.sh: 24: gera_boleto.sh: Syntax error: word unexpected (expecting "do")

  2. #2
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Problem with shell script

    Code:
    for PDF in *.pdf;
     do
    I think you should not have both ; and new line
    Code:
    for PDF in *.pdf
    do
    might work better

  3. #3
    Join Date
    Feb 2013
    Beans
    5

    Re: Problem with shell script

    also failed =/

  4. #4
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Problem with shell script

    No, semicolon is not a problem, even if it's redundant here.

    I guess it's how one of your PDF files is named what makes bash unhappy. Maybe an unusual character like # or parenthesis. Something like this.

    Place set -x before loop and watch how the script runs.
    Last edited by schragge; February 17th, 2013 at 03:02 PM.

  5. #5
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Problem with shell script

    Quote Originally Posted by schragge View Post
    No, semicolon is not a problem, even if it's redundant here.

    I guess it's how one of your PDF files is named what makes bash unhappy. Maybe an unusual character like # or parenthesis. Something like this.

    Place set -x before loop and watch how the script runs.
    I see your point

    Maybe I can add that it might be a problem with space in a name, try "$PDF" instead of $PDF and "$PDF2" instead of $PDF2

  6. #6
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Problem with shell script

    No, it's not space. Spaces are valid delimiters in the list.
    Last edited by schragge; February 17th, 2013 at 03:02 PM.

  7. #7
    Join Date
    Feb 2013
    Beans
    5

    Re: Problem with shell script

    I think the problem lies elsewhere, because this script also did not work, returned the same error.

    ----SCRIPT -------
    #!/bin/bash
    for i in 1 2 3 4 5
    do
    echo "teste $i"
    done

    ---- ERROR ---
    ts.sh: 3: ts.sh: Syntax error: word unexpected (expecting "do")

  8. #8
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Problem with shell script

    Check permissions of the script, see this thread.

    Update.
    Now I think it has nothing to do with permissions either. Ensure that the script doesn't contains CR (aka \r) characters. Either open it in vim, or do
    Code:
    od -c script.sh
    or try
    Code:
    tr '\r' @ < script.sh
    and watch for @
    Last edited by schragge; February 17th, 2013 at 03:12 PM.

  9. #9
    Join Date
    Feb 2013
    Beans
    5

    Re: Problem with shell script

    I'm logged in with User "servidor" and the file has the User "sistema" as owner.

    how do I change the file owner?

  10. #10
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Problem with shell script

    Code:
    sudo chown servidor file

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •