Argument to the script query


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Argument to the script query
# 1  
Old 11-08-2014
Wrench Argument to the script query

Hi,

I have a script invest.sh which takes two inputs i.e the name of the properties file and the file permissions for eg:

Code:
./invest.sh app12.properties 664

Now i wish to give a folder path /opt/app/properties instead of the properties file and the invest.sh script should lookout for all the files with the .properties extension in all the sub-directories and run the script for all the properties instead of single.

for eg:
Code:
./invest.sh /opt/app/properties 664

I m aware of the find command however, can you help me with teh snippet which will help me achieve this ?
# 2  
Old 11-09-2014
Did you consider the -R option of chmod?
# 3  
Old 11-09-2014
When you use:
Code:
chmod -R 664 directory

it changes the mode of the named directory and all files in the hierarchy below it.

To just change the mode of regular files with names ending with .properties in a hierarchy, try:
Code:
find directory -name '*.properties' -type f -exec chmod 664 '{}' +

# 4  
Old 11-09-2014
Quote:
Originally Posted by mohtashims
Now i wish to give a folder path /opt/app/properties instead of the properties file and the invest.sh script should lookout for all the files with the .properties extension in all the sub-directories and run the script for all the properties instead of single.
As Don Cragun already suggested use find with the -exec-clause:

Code:
find /path/to/directory -type -f -name "*.properties" -exec invest.sh {} <filemode> \;

But maybe you want to extend your script to do that automatically. Notice, in this case, that there is no difference between file names and directory names. You will have to use test -d and/or test -f to test for files or directories, like this:

Code:
if   [ -f "$1" ] ; then
     old_invest.sh "$1" "$2"
elif [ -d "$1" ] ; then
     find "$1" -type f -name "*.properties" -exec old_invest.sh {} $2 \;
else
     echo "Error: specify only directories or files." >&2
fi

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

2. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

3. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

4. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

5. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

6. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

7. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. UNIX for Dummies Questions & Answers

Script with an argument

I have a script named abc.sh and another script ab.sh I execute one as: ./abc.sh and another ./ab start that is with an argument , so wanted to know what is this start a file or something else? (4 Replies)
Discussion started by: nixhead
4 Replies

9. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

10. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies
Login or Register to Ask a Question