Array loops and checking if file exists
Quite simple problem I have here. I have made a script to automaticaly run files in folders in the current directory, to start multiple servers at once each from their own file. The problem with that is that the script assumes every folder in the current directory is a server, so for instance if the folder contained server1, server2, and notaserver, the script would try to run the start script in the notaserver folder even though it's not really a server. I need the script to check if the start.sh file exists in the server folder before it tries to execute it; if the file doesn't exist: don't attempt to execute it nor say that the folder/server was found.
Any help is appreciated. :) Below is the code used in the script. Please tell me what I have to add/remove/change/etc in order for this to happen. Code:
#!/bin/bash |
Quote:
As for your script: Do not parse ls, for reasons found here I fail to see where you test for the start.sh file?? Or is the issue you do not know how to test if a file exists? If not, I suggest you have a look at man test |
Quote:
Quote:
When I try to set the variable manualy, it won't set correctly and it errors out the script. Code:
root@ubuntu:/home# test=${test -e hub/start.sh} |
test is a command, why would you need {} or is this a typo and should have been ()?
As for: Quote:
|
Quote:
Code:
root@ubuntu:/home/mc# ./start Quote:
In other words, when the script lists all the directors in the current dir, check to make sure they have a start file in them before telling itself to later start a script in a folder which doesn't exist. The output of the command test would determin wether it would be included or not in the array. |
Well this works for me:
Code:
tmp=( */start.sh ) |
Quote:
|
All times are GMT -5. The time now is 11:06 AM. |