|
26-02-2010, 21:30 | #1 |
The Last Airbender
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
|
Script help....again :)
Been searching for an answer on this but it's all a bit over my head at the moment.
I have one directory with multiple directories inside it. I need to run the command "dpkg -b <directory name>" to create a deb package of that directory. Thing is, I want to be able to run it automatically for whatever directories are present. The command can also only handle one directory at a time. So, I need a script that will collect the directory names and then pass them on to that command one at a time until they are all done.
__________________
|
26-02-2010, 22:05 | #2 |
Screaming Orgasm
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
|
Ta-da:
find . -type d -exec dpkg -b {} \; 'Find everything, in the current directory (.), of type directory (-type d) and execute (-exec) the command dpkg -b'. The bits at the end are find's way of substituting parameters, so the directory will go where the {} is, and the \; signifies the end of the command. Last edited by Mark; 26-02-2010 at 22:10. |
26-02-2010, 22:15 | #3 |
The Last Airbender
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
|
Cheers Mark, that seems to have done the trick although it's not quite perfect
Can you make it so it only does the directories in the main directory? What it seems to be doing is running the command on as many sub-directories as it can find. Whilst this doesn't actually cause a problem as it can't find the control file to create the deb, it just gives a messy output. But thanks again as it does give the final files I need
__________________
|
26-02-2010, 22:25 | #4 |
Screaming Orgasm
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
|
find . -maxdepth 1 -type d -exec dpkg -b {} \;
You might need -maxdepth 2. I rarely get that one right. |
26-02-2010, 22:32 | #5 |
The Last Airbender
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
|
depth 1 worked a treat
__________________
|
27-02-2010, 02:23 | #6 |
Preparing more tumbleweed
Join Date: Jun 2006
Location: Hawaii
Posts: 6,038
|
To cover a geek angle it's worth emphasising the importance of -exec there.
Linux allows you to have filenames with spaces and other special characters in them, e.g. test file here to view or access the file those spaces need to be 'escaped' (preceeded by a \ symbol), e.g. Code:
$ cat test\ file\ here It's quite a common trick to pipe responses into xargs, e.g. Code:
find . -name "*here"| xargs cat Code:
# find . -name "*here" | xargs cat cat: ./test: No such file or directory cat: file: No such file or directory cat: here: No such file or directory -exec gets away with all that fuss, it makes sure whatever commands are carried out actually take place against the correct file / directory, leaving no room for mistakes (unless your entire concept is bad, but there is no helping that!) Code:
# find . -name "*here" -exec cat {} \; Boat Drinks
__________________
Mal: Define "interesting"? Wash: "Oh, God, oh, God, we're all gonna die"? |
27-02-2010, 10:28 | #7 |
Screaming Orgasm
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
|
And the other Geek angle is why *here was in quotes. Try it without (as all too often happens), and one of three things will happen:
|
27-02-2010, 15:12 | #8 |
The Last Airbender
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
|
Cheers guys
It's always nice to get a bit more info about these things just so I know why something is happening rather than just blindly copying it. Just so you know what it's for, my iPhone repo is now totally automatic I drop apps or themes in to folders and then run a script based on what repo it should go in to. It now automatically creates the deb based on all folders, creates a packages file, creates a zip of the packages file and uploads all of that to the webspace all with one click of a button
__________________
|