Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

I use technology in order to hate it more properly. -- Nam June Paik


devel / comp.unix.shell / Re: find my_script in multiple directories and execute it

SubjectAuthor
* find my_script in multiple directories and execute itHarry
+* find my_script in multiple directories and execute itJosef_Möllers
|`* find my_script in multiple directories and execute itHarry
| `* find my_script in multiple directories and execute itJanis Papanagnou
|  `- find my_script in multiple directories and execute itHarry
`* find my_script in multiple directories and execute itLew Pitcher
 `* find my_script in multiple directories and execute itHarry
  `- find my_script in multiple directories and execute itLew Pitcher

1
find my_script in multiple directories and execute it

<a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7242&group=comp.unix.shell#7242

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:1349:b0:3b9:b7f6:7cb0 with SMTP id w9-20020a05622a134900b003b9b7f67cb0mr1241821qtk.277.1675961399110;
Thu, 09 Feb 2023 08:49:59 -0800 (PST)
X-Received: by 2002:a0d:e692:0:b0:52e:c6d9:d760 with SMTP id
p140-20020a0de692000000b0052ec6d9d760mr45422ywe.243.1675961398856; Thu, 09
Feb 2023 08:49:58 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 9 Feb 2023 08:49:58 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=24.84.202.140; posting-account=0cwH1wkAAACyHC8RuqgGpRum9kOwb46T
NNTP-Posting-Host: 24.84.202.140
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>
Subject: find my_script in multiple directories and execute it
From: harryooopotter@hotmail.com (Harry)
Injection-Date: Thu, 09 Feb 2023 16:49:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1445
 by: Harry - Thu, 9 Feb 2023 16:49 UTC

I have my_script.sh in multiple directories.
How could I find it, then change directory there, and execute it, one by one?

../a/b c/d/my_script.sh
../e/f g/h/my_script.sh
....

find . -name 'my_script.sh' -exec (cd dirname of {} ; sh my_script.sh ) \;

I tried just echoing the dirname with no success ...
$ find . -name update_files_b0783.sh -exec echo ${{}%/*} \;
-bash: ${{}%/*}: bad substitution

Any help appreciated.
TIA

Re: find my_script in multiple directories and execute it

<k4knsoF45pgU1@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7243&group=comp.unix.shell#7243

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: josef@invalid.invalid (Josef Möllers)
Newsgroups: comp.unix.shell
Subject: Re: find my_script in multiple directories and execute it
Date: Thu, 9 Feb 2023 18:12:56 +0100
Lines: 24
Message-ID: <k4knsoF45pgU1@mid.individual.net>
References: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net Cb1okFjvTvZL0R95VHslTgiXmkue/t9EF4V8tY47x1XlNiYKBc
Cancel-Lock: sha1:mTJ2Dqg3dnHD+ft/4rFCCNKwlNs=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.7.1
Content-Language: en-US
In-Reply-To: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>
 by: Josef Möllers - Thu, 9 Feb 2023 17:12 UTC

On 09.02.23 17:49, Harry wrote:
> I have my_script.sh in multiple directories.
> How could I find it, then change directory there, and execute it, one by one?
>
> ./a/b c/d/my_script.sh
> ./e/f g/h/my_script.sh
> ...
>
> find . -name 'my_script.sh' -exec (cd dirname of {} ; sh my_script.sh ) \;
>
> I tried just echoing the dirname with no success ...
> $ find . -name update_files_b0783.sh -exec echo ${{}%/*} \;
> -bash: ${{}%/*}: bad substitution

My pragmatic solution: Whip up a script:
#! /bin/bash
dir="${1%/*}"
script="${1##*/}"
cd "$dir" && sh "$script"

Then use the script(name) as the argument to "-exec"

Josef

Re: find my_script in multiple directories and execute it

<ts3ak1$mogt$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7244&group=comp.unix.shell#7244

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: find my_script in multiple directories and execute it
Date: Thu, 9 Feb 2023 17:30:41 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 17
Message-ID: <ts3ak1$mogt$2@dont-email.me>
References: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 9 Feb 2023 17:30:41 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="a0ad817ff2e5c6854ed4a5ce0f8d4755";
logging-data="746013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19FkkigxLSVXrwat1j3ZGSJW5Y8i0rrhB0="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:6VSgkpQ80nUdwYvRT5ktX9c6BhQ=
 by: Lew Pitcher - Thu, 9 Feb 2023 17:30 UTC

On Thu, 09 Feb 2023 08:49:58 -0800, Harry wrote:

> I have my_script.sh in multiple directories.
> How could I find it, then change directory there, and execute it, one by
> one?
>
> ./a/b c/d/my_script.sh ./e/f g/h/my_script.sh ...
>
> find . -name 'my_script.sh' -exec (cd dirname of {} ; sh my_script.sh )
> \;

How about
find . -name 'my_script.sh' -print | while read SP ; do "$SP" ; done

--
Lew Pitcher
"In Skills We Trust"

Re: find my_script in multiple directories and execute it

<ed3ca6ff-b884-4559-b4f1-212f1aa7ef3an@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7245&group=comp.unix.shell#7245

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:570b:0:b0:3b9:bbba:f444 with SMTP id 11-20020ac8570b000000b003b9bbbaf444mr1796609qtw.164.1675966512511;
Thu, 09 Feb 2023 10:15:12 -0800 (PST)
X-Received: by 2002:a81:8042:0:b0:527:a383:964d with SMTP id
q63-20020a818042000000b00527a383964dmr1321595ywf.99.1675966512294; Thu, 09
Feb 2023 10:15:12 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 9 Feb 2023 10:15:12 -0800 (PST)
In-Reply-To: <k4knsoF45pgU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=24.84.202.140; posting-account=0cwH1wkAAACyHC8RuqgGpRum9kOwb46T
NNTP-Posting-Host: 24.84.202.140
References: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com> <k4knsoF45pgU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ed3ca6ff-b884-4559-b4f1-212f1aa7ef3an@googlegroups.com>
Subject: Re: find my_script in multiple directories and execute it
From: harryooopotter@hotmail.com (Harry)
Injection-Date: Thu, 09 Feb 2023 18:15:12 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1557
 by: Harry - Thu, 9 Feb 2023 18:15 UTC

On Thursday, February 9, 2023 at 9:13:03 AM UTC-8, Josef Möllers wrote:

> My pragmatic solution: Whip up a script:
> #! /bin/bash
> dir="${1%/*}"
> script="${1##*/}"
> cd "$dir" && sh "$script"
>
> Then use the script(name) as the argument to "-exec"

Josef,
It only went through one of the many directories.

Re: find my_script in multiple directories and execute it

<1a67d531-c879-48b7-8aa4-4ef768e0bf00n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7246&group=comp.unix.shell#7246

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:153:b0:3bb:760d:934b with SMTP id v19-20020a05622a015300b003bb760d934bmr1821498qtw.11.1675966799876;
Thu, 09 Feb 2023 10:19:59 -0800 (PST)
X-Received: by 2002:a25:dcc3:0:b0:8e6:15c7:e455 with SMTP id
y186-20020a25dcc3000000b008e615c7e455mr99146ybe.66.1675966799671; Thu, 09 Feb
2023 10:19:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 9 Feb 2023 10:19:59 -0800 (PST)
In-Reply-To: <ts3ak1$mogt$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.84.202.140; posting-account=0cwH1wkAAACyHC8RuqgGpRum9kOwb46T
NNTP-Posting-Host: 24.84.202.140
References: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com> <ts3ak1$mogt$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1a67d531-c879-48b7-8aa4-4ef768e0bf00n@googlegroups.com>
Subject: Re: find my_script in multiple directories and execute it
From: harryooopotter@hotmail.com (Harry)
Injection-Date: Thu, 09 Feb 2023 18:19:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1530
 by: Harry - Thu, 9 Feb 2023 18:19 UTC

On Thursday, February 9, 2023 at 9:30:51 AM UTC-8, Lew Pitcher wrote:

> How about
> find . -name 'my_script.sh' -print | while read SP ; do "$SP" ; done

Lew
I haven't tried your suggestion yet ...
It has to "cd <the destination directory>" first, because my_script.sh would try to copy files from some_directory to those already existing in <the destination directory>.

Re: find my_script in multiple directories and execute it

<ts3dk0$od4r$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7247&group=comp.unix.shell#7247

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: find my_script in multiple directories and execute it
Date: Thu, 9 Feb 2023 19:21:52 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <ts3dk0$od4r$1@dont-email.me>
References: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>
<k4knsoF45pgU1@mid.individual.net>
<ed3ca6ff-b884-4559-b4f1-212f1aa7ef3an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 9 Feb 2023 18:21:52 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ed9d34eb8d2592a8a438ab030447fd00";
logging-data="799899"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HrOBJ+h0blQqVUEWYBm32"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:Eq/q+xUnh8sTX+//jfPMmOxBl6o=
In-Reply-To: <ed3ca6ff-b884-4559-b4f1-212f1aa7ef3an@googlegroups.com>
 by: Janis Papanagnou - Thu, 9 Feb 2023 18:21 UTC

On 09.02.2023 19:15, Harry wrote:
> On Thursday, February 9, 2023 at 9:13:03 AM UTC-8, Josef Möllers wrote:
>
>> My pragmatic solution: Whip up a script:
>> #! /bin/bash
>> dir="${1%/*}"
>> script="${1##*/}"
>> cd "$dir" && sh "$script"
>>
>> Then use the script(name) as the argument to "-exec"
>
> Josef,
> It only went through one of the many directories.
>

What if you expand the loop in shell...?

find -name "my_script.sh" |
while read f ; do ( cd "${f%/*}" && sh "${f##*/}" ) ; done

But note that you need adjustments for pathological filenames.

Also it might be worth a thought in case it's possible that
malicious files in the directory hierarchy might be executed.

Janis

Re: find my_script in multiple directories and execute it

<ts3f9p$o7ii$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7248&group=comp.unix.shell#7248

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: find my_script in multiple directories and execute it
Date: Thu, 9 Feb 2023 18:50:33 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 17
Message-ID: <ts3f9p$o7ii$1@dont-email.me>
References: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>
<ts3ak1$mogt$2@dont-email.me>
<1a67d531-c879-48b7-8aa4-4ef768e0bf00n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 9 Feb 2023 18:50:33 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="a0ad817ff2e5c6854ed4a5ce0f8d4755";
logging-data="794194"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/knHKYyYqAhiu4HuxPM39f3Tf4NkazDoo="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:qNrNVjlxbZfE2TT4RH0dpTR/A5E=
 by: Lew Pitcher - Thu, 9 Feb 2023 18:50 UTC

On Thu, 09 Feb 2023 10:19:59 -0800, Harry wrote:

> On Thursday, February 9, 2023 at 9:30:51 AM UTC-8, Lew Pitcher wrote:
>
>> How about find . -name 'my_script.sh' -print | while read SP ; do "$SP"
>> ; done
>
> Lew I haven't tried your suggestion yet ...
> It has to "cd <the destination directory>" first, because my_script.sh
> would try to copy files from some_directory to those already existing in
> <the destination directory>.

That's fair. My suggestion doesn't do that.

--
Lew Pitcher
"In Skills We Trust"

Re: find my_script in multiple directories and execute it

<be5aa04d-6968-4d10-adb3-4c91689f0596n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7249&group=comp.unix.shell#7249

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:84:b0:3b9:bfac:8327 with SMTP id o4-20020a05622a008400b003b9bfac8327mr1784920qtw.315.1675970760003;
Thu, 09 Feb 2023 11:26:00 -0800 (PST)
X-Received: by 2002:a5b:388:0:b0:8c6:51c5:4896 with SMTP id
k8-20020a5b0388000000b008c651c54896mr519581ybp.272.1675970759764; Thu, 09 Feb
2023 11:25:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 9 Feb 2023 11:25:59 -0800 (PST)
In-Reply-To: <ts3dk0$od4r$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.84.202.140; posting-account=0cwH1wkAAACyHC8RuqgGpRum9kOwb46T
NNTP-Posting-Host: 24.84.202.140
References: <a7fb9eaf-d5a6-41f7-9f71-e2afe05a7b33n@googlegroups.com>
<k4knsoF45pgU1@mid.individual.net> <ed3ca6ff-b884-4559-b4f1-212f1aa7ef3an@googlegroups.com>
<ts3dk0$od4r$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <be5aa04d-6968-4d10-adb3-4c91689f0596n@googlegroups.com>
Subject: Re: find my_script in multiple directories and execute it
From: harryooopotter@hotmail.com (Harry)
Injection-Date: Thu, 09 Feb 2023 19:25:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1828
 by: Harry - Thu, 9 Feb 2023 19:25 UTC

On Thursday, February 9, 2023 at 10:21:57 AM UTC-8, Janis Papanagnou wrote:

> What if you expand the loop in shell...?
>
> find -name "my_script.sh" |
> while read f ; do ( cd "${f%/*}" && sh "${f##*/}" ) ; done
>
> But note that you need adjustments for pathological filenames.
>
> Also it might be worth a thought in case it's possible that
> malicious files in the directory hierarchy might be executed.
>
> Janis

Janis

It works.
Thanks a lot for your help.

H.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor