Executing all scripts in /DIR except one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing all scripts in /DIR except one
# 1  
Old 12-25-2009
Executing all scripts in /DIR except one

First i need to find all scripts directly under /DIR that end with ".sh" extension except "noallow.sh". That can be done with:

Code:
find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh"

Now i want to run all the files output from the previous command.

The following code:

Code:
for filename in $(find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh")
do
/DIR/${filename}
done

Can do the job. But i want to know can this whole thing be done by using find only with exec {}.
# 2  
Old 12-25-2009
It can even be done without find:

ksh (and zsh with kshglob enabled):

Code:
for s in "$path"/!(noallow).sh; do "$s"; done

For bash you should enable extended glob with:

Code:
shopt -s extglob

Regarding your question for find/exec:

HTML Code:
find "$path" -maxdepth 1 -name '*.sh' ! -name 'noallow.sh' -exec {} \;
# 3  
Old 12-25-2009
Quote:
Originally Posted by proactiveaditya
Code:
for filename in $(find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh")
do
/DIR/${filename}
done


Code:
dir=/path/to/wherever
for script in "$dir"/*.sh
do
  case $script in "$dir"/noallow.sh) continue ;; esac
  "$script"
done

# 4  
Old 12-25-2009
--others had posted the same--
# 5  
Old 12-25-2009
Code:
find "$path" -maxdepth 1 -name '*.sh' ! -name 'noallow.sh' -exec {} \;

Now can i echo/print the name of the script before running it and all this using find command?
# 6  
Old 12-25-2009
Quote:
Originally Posted by proactiveaditya
Code:
find "$path" -maxdepth 1 -name '*.sh' ! -name 'noallow.sh' -exec {} \;

Now can i echo/print the name of the script before running it and all this using find command?

Code:
find "$path"/*.sh ! -name noallow.sh -print -exec {} \;


Last edited by cfajohnson; 12-25-2009 at 04:51 PM..
# 7  
Old 12-25-2009
Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing multiple scripts using if condition

I have an if condition. If that condition is true then one script will be run and after that I need to check another condition based on the output value of first script. i tried like below : cd lock if ; then rm exitup if ; then kb_shutdown kb_startup if ; then rm exitup if ;... (3 Replies)
Discussion started by: charanarjun
3 Replies

2. Shell Programming and Scripting

Print filename/dir name while executing aclput using find command

Running below command , but unable to print the filename , is there way to print filename/dirname using -print option find . -type f -exec aclput -i fileacl.template {} \; (5 Replies)
Discussion started by: lalitpct
5 Replies

3. Shell Programming and Scripting

how to get the scripts full dir path

lyang0@lyang0-OptiPlex-755:~$ ./test.sh . lyang0@lyang0-OptiPlex-755:~$ cat test.sh #!/bin/bash echo `dirname $0` lyang0@lyang0-OptiPlex-755:~$ pwd /home/lyang0 it doesn't get "/home/lyang0" and only when run /home/lyang0/test.sh it will get, but how can I do, then it can get the real... (8 Replies)
Discussion started by: yanglei_fage
8 Replies

4. Shell Programming and Scripting

Executing several bash scripts in succession

Hi, I am new to shell programming. I am trying to automate setting up a network using several scripts. Some of the scripts require to reboot in order to continue with the setup. Is it possible to enter another script as soon as the system reboots. Also, if the last line of the script is bash... (7 Replies)
Discussion started by: fantasyland
7 Replies

5. Shell Programming and Scripting

executing shell scripts in a browser

Hi all Im a newbie in shell scripting, i found it joyous creating simple adminitrative scripts, like adding users, modify and delete, remote sw install etc, now i want to intergrate my scripts to make a simple administrative tool, how do i access the scripts via a browser is it possible?? ... (2 Replies)
Discussion started by: jefinah
2 Replies

6. UNIX for Dummies Questions & Answers

Executing scripts in back ground

Hi, Test1.ksh #! /bin/ksh for i in $* do #echo "$i" ksh test2.ksh $i & done test2.ksh #! /bin/ksh sleep 5s echo "From Test 1 ==> $1" exit 0; I am executing as follows: ksh test1.ksh a b c (10 Replies)
Discussion started by: risshanth
10 Replies

7. Shell Programming and Scripting

Executing scripts in Parallel

Hi All, I have 3 shell scripts, Script1,Script2 and Script3. Now I want to run Script1 and Script2 in parallel and Script3 should depend on successful completion of both Script1 and Script2. Could you please suggest an approach of acheiving this... Thanks in advance (2 Replies)
Discussion started by: itsme_maverick
2 Replies

8. UNIX for Dummies Questions & Answers

Executing Shell Scripts

Hi, I'm pretty new to Unix and I just have a question concerning making a script executable without putting the "sh" command before it. In case it makes the difference I am on an Apple computer using the Terminal. Anyway here is the little test code I wrote followed by the commands I took to try... (1 Reply)
Discussion started by: BuyoCat
1 Replies

9. Shell Programming and Scripting

executing variables in ksh scripts?

In a ksh script on an AIX box running a jillion oracle database processes, I'm setting a variable to one of two possible arguments, depending on cmd line arguments. FINDIT="ps -ef | grep oracle | grep DBexport | grep rshrc" -or- FINDIT="ps -ef | grep oracle | grep prod | grep runback" I... (3 Replies)
Discussion started by: zedmelon
3 Replies

10. UNIX for Advanced & Expert Users

executing perl scripts

Does anybody experiencing this same problem? I am using IRIX64 ver 6.5 at work. I wrote some Perl scripts and to execute it. First I try to put the Perl script at: /$HOME/bin/perlscript then I set the correct executable 755 right to the file I make sure the PATH to the executable... (2 Replies)
Discussion started by: vtran4270
2 Replies
Login or Register to Ask a Question