Execute commands to specific folder from input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute commands to specific folder from input file
# 1  
Old 05-21-2010
Execute commands to specific folder from input file

Hi,
I have one text file input.txt, which has folders path as follows:

Code:
/home/user/automate/abc
/home/user/automate/abc/xyz
/home/user/automate/test
/home/user/automate/test2
/home/user/automate/test2/abc/Main

In those folders i have .svn folder.
1) First i want to remove .svn like rm -rf
2) initialize git repository in those folders ie, run git init command.

Please note that under /home/userautomate/ also have many other folders ~100.I dont want to touch those ( which will have .svn ).
I could go with for loop for all the folders but i want the script to take input as input.txt file.

I would appreciate all your help Smilie.

Last edited by Yogesh Sawant; 05-21-2010 at 04:35 AM.. Reason: added code tags
# 2  
Old 05-21-2010
Here is a basic for loop that reads from the input file line by line. You add your operation you want to do

Code:
for dirname in *;
do
  #delete your folder or what ever you want
echo $dirname
done < input.txt

# 3  
Old 05-21-2010
Quote:
Originally Posted by amitranjansahu
Here is a basic for loop that reads from the input file line by line. You add your operation you want to do

Code:
for dirname in *;
do
  #delete your folder or what ever you want
echo $dirname
done < input.txt

Hi amitranjansahu,

This command will do the action for all the files/dir under the current directory.
this has nothing to do with input.txt

@dragon.1431: please don't execute this command with the delete option directly on your file. else that will delete all the files.


try something like:



Code:
while read path
do
 echo "cd $path || echo unable to change $path"
 echo "rm -rf .svn"
 echo "run git init"
done < file

I have put echo for safely instead of commands. please test first instead applying directly.
# 4  
Old 05-21-2010
Hi Anchal . sorry for the confusion. I just intend to give the idea to get the path from the input file. Thats why i mentioned to change the script as per the need by adding the extra code. Any way thanks for pointing out the concern
# 5  
Old 05-21-2010
Yes, I understood your intention and that's why I pointed that "*" MUST not be used to read the path from the file.
probably, you would have something different in your mind ( something like while read, since you used indirection). but missed that unintentionally.

I told that because I faced this couple of times with myself. Smilie
# 6  
Old 05-21-2010
Hi,
thanks anchal_khare.It works as expected.
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 execute a batch file containing ftp commands??

hi, is there a way i can execute a batch file containing ftp commands like we execute sftp batch file. sftp -b batchfile user@server > output how to create a batch file for ftp executing command and how to run the batch file from a shell script? (2 Replies)
Discussion started by: Little
2 Replies

2. Shell Programming and Scripting

How to take input from the user from the command line and execute commands basedon that?

Hi, I am using solaris 10 and bash shell.Script execution follows below.Initially it will check whether a directory exists or not if does not exist it will create it.(This I have completed) Second step:I have four users say user1,user2,user3,user4.Script should prompt for the user id and... (11 Replies)
Discussion started by: muraliinfy04
11 Replies

3. Shell Programming and Scripting

Shell: How to execute commands from another file?

I made a configuration file for my shell script in that all the values that the shell scipt needs, are defined, but I don't know how to let the shell script use those defined variables. Thank you for your help :) (3 Replies)
Discussion started by: Alkali
3 Replies

4. UNIX for Dummies Questions & Answers

Using any file in folder as command input

Hi all, I have a command I need to run on a large number of folders. It needs only one input, namely one of the 150 files in the folder (doesn't matter which one): command filenameThe problem is that the names of the files are random, so I was trying to just get the first file by using list and... (5 Replies)
Discussion started by: Linnnnn
5 Replies

5. Shell Programming and Scripting

How to copy specific file.txt in specific folder?

hye there... i have a problem to copy file in specific folder that will change the name according to host,time(%m%s) and date(%Y%M%D) example folder name: host_20100531.154101801 this folder name will always change... but i just want to copy the AAA.txt and BBB.txt file.. really need... (17 Replies)
Discussion started by: annetote
17 Replies

6. Shell Programming and Scripting

How to execute commands read from another file?

Please help with this simple example. I can not figure out how to do it. A file named “job” contains only this one line:var=5I need a script to read the job file and execute it as a command. This is my attempt (it does not work):#!/bin/sh exec < job echo "var = $var"output should read “var = 5”... (5 Replies)
Discussion started by: wolfv
5 Replies

7. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

8. UNIX for Advanced & Expert Users

Execute All Commands in A contrl File

Hi , I have a situation i need to write a while loop until the end of control file.In the control file i have a 5 lines which contains commands.how can i execute all with out waiting for the first one to complete. Ex ControlFile: ScripitName Test ScriptName Test1 ScriptName Test2 ... (1 Reply)
Discussion started by: ukatru
1 Replies

9. Shell Programming and Scripting

Pls Help-Script to execute Commands and write to excel file

Execute some commands in script and store result in excel sheet Kindly help me........... (1 Reply)
Discussion started by: Computer_baby
1 Replies

10. Shell Programming and Scripting

Can Xargs execute multiple commands of evry input file

Hello , I am trying to print the footer of evry file in the given directory with xargs command like follows ls -1 | xargs -I {} gzcat {} | tail -1 now problem with this is only last file foooter is getting printed as " | tail -1 " is getting executed for the last file. I know this can... (4 Replies)
Discussion started by: nilesrex
4 Replies
Login or Register to Ask a Question