Results 1 to 2 of 2
I'm attempting to write a script that will create a set of files and directories from a file of data, this must be able to be edited dynamically from the ...
- 05-13-2008 #1Just Joined!
- Join Date
- May 2008
- Posts
- 2
Directory building script
I'm attempting to write a script that will create a set of files and directories from a file of data, this must be able to be edited dynamically from the data file, so this can't be a script full of commands.
Here is the script so far:
Don't worry about the $owner and $group at the moment.Code:#!/bin/bash ################################################################# # The datafile is called and defined here # ################################################################# while read inputline do name="$(echo $inputline | cut -d "," -f1)" fileordir="$(echo $inputline | cut -d "," -f2)" owner="$(echo $inputline | cut -d "," -f3)" group="$(echo $inputline | cut -d "," -f4)" ownper="$(echo $inputline | cut -d "," -f5)" groupper="$(echo $inputline | cut -d "," -f6)" otherper="$(echo $inputline | cut -d "," -f7)" echo $name $fileordir $owner $group $ownper $groupper $otherper ################################################################# # Files and directories are created here # ################################################################# if [ "$fileordir" = "f" ]; then touch $name # Clears all permissions # chmod ugoa-rwx $name # Adds permissions for the user # chmod u+$ownper $name # Adds permissions for groups # chmod g+$groupper $name # Adds permissions for others # chmod o+$otherper $name else mkdir $name # Clears all permissions # chmod ugoa-rwx $name # Adds permissions for the user # chmod u+$ownper $name # Adds permissions for the groups # chmod g+$groupper $name # Adds permissions for others # chmod o+$otherper $name exit fi done < /home/test/data.txt
However, I'm running into a problem, the script only creates the file/directory (Which it does great so far) for the first line of the data file, how can I get it so it does every line of the datafile, rather than just the first?
here's a draft of the data file:
##name, type, owner, group, permissions##
directory_test ,d,test,hnd,rwx,rx,x “End of line”
file_test,f,root,root,rw, , “End of line”
The “End of line” is not part of the data file
.
The reason the spaces are blank in the permissions area (The last three) so that the chmod part of the script does not add any permissions that has been taken away by “chmod ugoa-rwx $name”.
- 05-14-2008 #2
I think you need some curly brackets. Here is an example of while usage
while {$x<10} {
puts "x is $x"
incr x
}
Basically you never closed the looping structure.
I don't think 'do' is needed.


Reply With Quote