Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"I prefer rogues to imbeciles, because they sometimes take a rest." -- Alexandre Dumas (fils)


devel / comp.unix.shell / Bash passing a variable to another script using a while loop vs an arg

SubjectAuthor
* Bash passing a variable to another script using a while loop vs an argChris Roberts
+- Re: Bash passing a variable to another script using a while loop vsJanis Papanagnou
`* Re: Bash passing a variable to another script using a while loop vsEd Morton
 `- Re: Bash passing a variable to another script using a while loop vsChris Roberts

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

<8d4a547e-080b-4ae1-8f16-0b02fd11dd87n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5146&group=comp.unix.shell#5146

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:31a0:b0:67d:7500:1752 with SMTP id bi32-20020a05620a31a000b0067d75001752mr13366202qkb.485.1647886116270;
Mon, 21 Mar 2022 11:08:36 -0700 (PDT)
X-Received: by 2002:a05:6214:622:b0:441:2825:c288 with SMTP id
a2-20020a056214062200b004412825c288mr4328722qvx.79.1647886115975; Mon, 21 Mar
2022 11:08:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 21 Mar 2022 11:08:35 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=4.79.195.162; posting-account=tSqayAoAAADEbq2bVxu4ODgY7tmW5dUx
NNTP-Posting-Host: 4.79.195.162
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8d4a547e-080b-4ae1-8f16-0b02fd11dd87n@googlegroups.com>
Subject: Bash passing a variable to another script using a while loop vs an arg
From: thecjg...@gmail.com (Chris Roberts)
Injection-Date: Mon, 21 Mar 2022 18:08:36 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 44
 by: Chris Roberts - Mon, 21 Mar 2022 18:08 UTC

########
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
#########

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

<t1ak39$ihe$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5147&group=comp.unix.shell#5147

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Bash passing a variable to another script using a while loop vs
an arg
Date: Mon, 21 Mar 2022 20:36:09 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <t1ak39$ihe$1@dont-email.me>
References: <8d4a547e-080b-4ae1-8f16-0b02fd11dd87n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Mar 2022 19:36:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a48591383945bfd3055d6e6b66b5f5e7";
logging-data="18990"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18F1NkA/Uek6n50NNaeZyOv"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:QOPuU7iou074Vq7VBSHepLzR8z8=
In-Reply-To: <8d4a547e-080b-4ae1-8f16-0b02fd11dd87n@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Mon, 21 Mar 2022 19:36 UTC

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
> #########
>

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

<t1al03$tv0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5148&group=comp.unix.shell#5148

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Bash passing a variable to another script using a while loop vs
an arg
Date: Mon, 21 Mar 2022 14:51:31 -0500
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <t1al03$tv0$1@dont-email.me>
References: <8d4a547e-080b-4ae1-8f16-0b02fd11dd87n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Mar 2022 19:51:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5de92ae3e80f04f5793bb4e27404c3cd";
logging-data="30688"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PoXn6fHSqgaOEkqMMzQvu"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:uYcYHBSaAgqcjeRaOIfVTLL7Aas=
In-Reply-To: <8d4a547e-080b-4ae1-8f16-0b02fd11dd87n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 220321-0, 3/20/2022), Outbound message
 by: Ed Morton - Mon, 21 Mar 2022 19:51 UTC

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
> #########

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

<00fdfb3a-d4ea-4223-b58f-1436d56468f7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5194&group=comp.unix.shell#5194

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:254d:b0:67e:3a57:8119 with SMTP id s13-20020a05620a254d00b0067e3a578119mr10896504qko.690.1648313879630;
Sat, 26 Mar 2022 09:57:59 -0700 (PDT)
X-Received: by 2002:ac8:5889:0:b0:2e1:afa2:65a9 with SMTP id
t9-20020ac85889000000b002e1afa265a9mr14145160qta.268.1648313879431; Sat, 26
Mar 2022 09:57:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 26 Mar 2022 09:57:59 -0700 (PDT)
In-Reply-To: <t1al03$tv0$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=173.79.137.133; posting-account=tSqayAoAAADEbq2bVxu4ODgY7tmW5dUx
NNTP-Posting-Host: 173.79.137.133
References: <8d4a547e-080b-4ae1-8f16-0b02fd11dd87n@googlegroups.com> <t1al03$tv0$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <00fdfb3a-d4ea-4223-b58f-1436d56468f7n@googlegroups.com>
Subject: Re: Bash passing a variable to another script using a while loop vs
an arg
From: thecjg...@gmail.com (Chris Roberts)
Injection-Date: Sat, 26 Mar 2022 16:57:59 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 60
 by: Chris Roberts - Sat, 26 Mar 2022 16:57 UTC

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.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor