• Bash passing a variable to another script using a while loop vs an arg

    From Chris Roberts@21:1/5 to All on Mon Mar 21 11:08:35 2022
    ########
    Perhaps someone out there could assist?
    I am having an issue using my script. It works fine when I feed it an inline argument, but NOT when I get the argument from a list and pass it as a variable.

    WORKS: "Scriptname encr1": I put the filename to encrypt as an arg to this script.
    It then passes to my expect script which encrypts just fine. (using openssl) #FILENAME="${1%}"
    #encrit.exp "$FILENAME" "$FILENAME.enc"

    NOT WORKING:"enc2-lab" I read filename from a list using a while loop.
    It then pass this to that same working expect encryption script.
    But, in this case, it produces an empty zero byte filename.enc file.
    #while read -r line;
    #do
    #encrit.exp "${line}" "${line}.enc"
    ----
    WORKING:

    Dell$ encr1 blah.pdf
    USAGE: $>encr1 filename-to-encrypt
    The filename to encrypt is "blah.pdf"
    blah.pdf exists
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 75999 bytes)
    -----
    NOT WORKING: (scriptname enc2-lab): This script gathers the argument from a file and then uses it to run the above command.
    #encrit.exp "$file" "$file.enc" #This way only works on the 1st loop, enc files are 0 bytes

    The above command seems to process it, but then we end up with a zero byte empty file.?
    Dell$ enc2-lab
    --Current line is /mnt/c/TMP/blah.pdf ---
    Line 1 is This is a file ( "/mnt/c/TMP/blah.pdf" )
    ENCRYPTING FILE. /mnt/c/TMP/blah.pdf
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 0 bytes)

    Note that the above output is a useless empty file.
    ----
    thanks,
    crzzy1
    #########

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Chris Roberts on Mon Mar 21 20:36:09 2022
    I suggest to try to post coherent code instead of the fragments of
    the dis-functional trash we see below.

    Why are all lines commented out with '#' ?
    Why do you use the '%' in ${1%} ?
    Why didn't you close the loop with 'done' ?
    What is the called syntax you used ?

    For a start you may call your script with the -x option, as in
    sh -x your_script your_args
    to see what's going on.

    And reduce your scripts to the essentials before re-posting.

    Good luck!

    On 21.03.2022 19:08, Chris Roberts wrote:
    ########
    Perhaps someone out there could assist?
    I am having an issue using my script. It works fine when I feed it an inline argument, but NOT when I get the argument from a list and pass it as a variable.

    WORKS: "Scriptname encr1": I put the filename to encrypt as an arg to this script.
    It then passes to my expect script which encrypts just fine. (using openssl) #FILENAME="${1%}"
    #encrit.exp "$FILENAME" "$FILENAME.enc"

    NOT WORKING:"enc2-lab" I read filename from a list using a while loop.
    It then pass this to that same working expect encryption script.
    But, in this case, it produces an empty zero byte filename.enc file.
    #while read -r line;
    #do
    #encrit.exp "${line}" "${line}.enc"
    ----
    WORKING:

    Dell$ encr1 blah.pdf
    USAGE: $>encr1 filename-to-encrypt
    The filename to encrypt is "blah.pdf"
    blah.pdf exists
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
    enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 75999 bytes)
    -----
    NOT WORKING: (scriptname enc2-lab): This script gathers the argument from a file and then uses it to run the above command.
    #encrit.exp "$file" "$file.enc" #This way only works on the 1st loop, enc files are 0 bytes

    The above command seems to process it, but then we end up with a zero byte empty file.?
    Dell$ enc2-lab
    --Current line is /mnt/c/TMP/blah.pdf ---
    Line 1 is This is a file ( "/mnt/c/TMP/blah.pdf" )
    ENCRYPTING FILE. /mnt/c/TMP/blah.pdf
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
    enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 0 bytes)

    Note that the above output is a useless empty file.
    ----
    thanks,
    crzzy1
    #########


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ed Morton@21:1/5 to Chris Roberts on Mon Mar 21 14:51:31 2022
    On 3/21/2022 1:08 PM, Chris Roberts wrote:
    ########
    Perhaps someone out there could assist?

    Copy/paste your code into http://shellcheck.net, fix the issues it tells
    you about, and then if you still have a problem post that corrected
    script you want help with here.

    Ed.

    I am having an issue using my script. It works fine when I feed it an inline argument, but NOT when I get the argument from a list and pass it as a variable.

    WORKS: "Scriptname encr1": I put the filename to encrypt as an arg to this script.
    It then passes to my expect script which encrypts just fine. (using openssl) #FILENAME="${1%}"
    #encrit.exp "$FILENAME" "$FILENAME.enc"

    NOT WORKING:"enc2-lab" I read filename from a list using a while loop.
    It then pass this to that same working expect encryption script.
    But, in this case, it produces an empty zero byte filename.enc file.
    #while read -r line;
    #do
    #encrit.exp "${line}" "${line}.enc"
    ----
    WORKING:

    Dell$ encr1 blah.pdf
    USAGE: $>encr1 filename-to-encrypt
    The filename to encrypt is "blah.pdf"
    blah.pdf exists
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
    enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 75999 bytes)
    -----
    NOT WORKING: (scriptname enc2-lab): This script gathers the argument from a file and then uses it to run the above command.
    #encrit.exp "$file" "$file.enc" #This way only works on the 1st loop, enc files are 0 bytes

    The above command seems to process it, but then we end up with a zero byte empty file.?
    Dell$ enc2-lab
    --Current line is /mnt/c/TMP/blah.pdf ---
    Line 1 is This is a file ( "/mnt/c/TMP/blah.pdf" )
    ENCRYPTING FILE. /mnt/c/TMP/blah.pdf
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
    enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 0 bytes)

    Note that the above output is a useless empty file.
    ----
    thanks,
    crzzy1
    #########

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Roberts@21:1/5 to Ed Morton on Sat Mar 26 09:57:59 2022
    On Monday, March 21, 2022 at 3:51:36 PM UTC-4, Ed Morton wrote:
    On 3/21/2022 1:08 PM, Chris Roberts wrote:
    ########
    Perhaps someone out there could assist?
    Copy/paste your code into http://shellcheck.net, fix the issues it tells
    you about, and then if you still have a problem post that corrected
    script you want help with here.

    Ed.
    I am having an issue using my script. It works fine when I feed it an inline argument, but NOT when I get the argument from a list and pass it as a variable.

    WORKS: "Scriptname encr1": I put the filename to encrypt as an arg to this script.
    It then passes to my expect script which encrypts just fine. (using openssl)
    #FILENAME="${1%}"
    #encrit.exp "$FILENAME" "$FILENAME.enc"

    NOT WORKING:"enc2-lab" I read filename from a list using a while loop.
    It then pass this to that same working expect encryption script.
    But, in this case, it produces an empty zero byte filename.enc file.
    #while read -r line;
    #do
    #encrit.exp "${line}" "${line}.enc"
    ----
    WORKING:

    Dell$ encr1 blah.pdf
    USAGE: $>encr1 filename-to-encrypt
    The filename to encrypt is "blah.pdf"
    blah.pdf exists
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
    enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 75999 bytes) -----
    NOT WORKING: (scriptname enc2-lab): This script gathers the argument from a file and then uses it to run the above command.
    #encrit.exp "$file" "$file.enc" #This way only works on the 1st loop, enc files are 0 bytes

    The above command seems to process it, but then we end up with a zero byte empty file.?
    Dell$ enc2-lab
    --Current line is /mnt/c/TMP/blah.pdf ---
    Line 1 is This is a file ( "/mnt/c/TMP/blah.pdf" )
    ENCRYPTING FILE. /mnt/c/TMP/blah.pdf
    spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
    enter aes-256-cbc encryption password:
    Verifying - enter aes-256-cbc encryption password:
    ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 0 bytes)

    Note that the above output is a useless empty file.
    ----
    thanks,
    crzzy1
    #########

    I found out my issue.
    There was no real error in the script.
    It was working in a stand alone script, but NOT within a while loop.
    I just had do add "sleep 1" after the command to give it time to process.

    Thank you to all those who replied.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)