Find all bash scripts on system


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find all bash scripts on system
# 1  
Old 09-26-2014
Find all bash scripts on system

I want to find all bash scripts on my system.
What I have so far is this:

Code:
find / -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \) | xargs -I{}  head -1 {} |grep bash

This will find all executables, read the first line and diplay it, if it contains "bash". Almost done, but I also need the filename and path of the bash script.

Any ideas?

Environment is AIX / ksh.
# 2  
Old 09-26-2014
find / -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \) -name "*.sh"
# 3  
Old 09-26-2014
I'm looking for bash scripts only.
# 4  
Old 09-26-2014
Perhaps something like :
Code:
find / -type f -name '*.sh' -exec head -1 {} /dev/null \;  | awk '/bash/ { print file } { file = $0 } '

This User Gave Thanks to Peasant For This Post:
# 5  
Old 09-26-2014
Quote:
Originally Posted by Peasant
Perhaps something like :
Code:
find / -type f -name '*.sh' -exec head -1 {} /dev/null \;  | awk '/bash/ { print file } { file = $0 } '


Thanks, but do bash scripts necessarily end with .sh ?

What I came up with by now is:
Code:
find / -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \)  -exec grep "^#!.*/bash" {} /dev/null \;|tee bashfiles

that also makes use of your trick with the appended /dev/null.
# 6  
Old 09-26-2014
My 2 cents:
I would test that files are ascii and not binary before using a grep... Peasant's solution avoids the problem since I dont know any binary executable name finishing with a suffix .sh ... only as you have pointed the use of a suffix is up to you and many script may have no suffixes...
# 7  
Old 09-26-2014
Personally, I would remove the clause stating that the files have to end .sh This is not necessarily the case. There will be many scripts on your server that may be supplied code that may not have this suffix. Unlike Windows, the suffix is not important, so you cannot be sure that all scripts will have it.

The checking for executable permissions is also flawed as scripts can be sourced (i.e. read into) the current shell and do not need to be executable, just readable.


I hope that this helps,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash -c interactive scripts

i have to run the following script through a pipe: script.sh: #!/bin/bash echo "Hello World" echo -e "The \033 here's how its currently being run: bash -c "$(cat script.sh)" This is an interactive script. the problem is, when i run it this way, if you go to another terminal and... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

Merge two bash scripts

I am currently running the following two bash scripts, in order to start x, matchbox and midori on the raspberry pi hdmi, using a remote ssh session. start-browser #!/bin/bash # import variables source /var/rpi/scripts/config/variables/general echo "starting browser" DISPLAY=:0.0 sudo xinit... (2 Replies)
Discussion started by: aristosv
2 Replies

3. Shell Programming and Scripting

Bash interactive scripts

i have a script that contains: script.sh #!/bin/bash echo -e "\t\t\t0. Exit" echo -e "\t\t\t1. Help" echo -e "\t\t\t2. Notes" echo -e "\t\t\t3. Classes" echo "${newline}" echo -n -e "\t Please enter option number : " read Type case $Type in 1) clear ... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

Parallel bash scripts

Need some help to replace bash script with parallel to speed up job on multiple files (400files.list is the file contains the absolute path to those 400 files). The bash script is to run the same program over the files repetitively. My bash_script.sh is: for sample in `cat 400files.list`; do... (3 Replies)
Discussion started by: yifangt
3 Replies

5. Shell Programming and Scripting

doxygen and bash scripts

I am trying to have doxygen documenting my bash scripts by setting the following in my Doxyfile FILE_PATTERNS = *.sh *.awk INPUT_FILTER = "sed -e 's|##|//!|'" FILTER_SOURCE_FILES = YES # Set path to bash scripts V=$(readlink -f"$0") bashpath="${V%/*}" # Set ANSI color... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

Bash scripts as commands

Hello, the bulk of my work is run by scripts. An example is as such: #!/bin/bash awk '{print first line}' Input.in > Intermediate.ter awk '{print second line}' Input.in > Intermediate_2.ter command Intermediate.ter Intermediate_2.ter > Output.out It works the way I want it to, but it's not... (1 Reply)
Discussion started by: Leo_Boon
1 Replies

7. Homework & Coursework Questions

Bash shell scripts

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Test that exactly one command line argrument is enter from the command line. If not, display the usage... (1 Reply)
Discussion started by: jcoop12
1 Replies

8. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

9. Shell Programming and Scripting

Nonblocking I/O in bash scripts

Hello, Is there a way to perform nonblocking I/O reads from standard input in a bash script? For example, in C, you can say: int flags = fcntl(STDIN_FILENO, F_GETFL); fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK); ch = fgetc(stdin); the 'fgetc' function will not block on... (5 Replies)
Discussion started by: neked
5 Replies
Login or Register to Ask a Question