Where <xxx> can be any number and name of directories.
<yyy> can be another set of any number of names and directories.
I want to neglect [do not wish to allocated them to variables] all the <xxx> and <yyy> folders that do not have the the complete path uptil [logs] directory as shown above.
Assuming that you want to process these directories one-by one we can create a while loop and only have one environment variable set per directory process.
Code:
ls -1d /appl/user_projects/domains/*/servers/*/logs 2>/dev/null | while read dir
do
echo "${dir}"
dc=$(basename $(dirname "${dir}"))
echo $dc
domain=$(basename $(dirname $(dirname $(dirname "${dir}"))))
echo $domain
done
There are tidier ways of extracting the dc and domain name fields but it depends on what Shell you have.
Last edited by methyl; 06-07-2012 at 12:35 PM..
Reason: Remove test code
Hello
Im pretty new to scripting in linux but am keen to learn.
I'm trying to create a backup script similar to a batch script I developed for windows (dos) where the backup is to a usb drive. no problems with the backup process but what I would like to do is automatically remove old files if... (2 Replies)
First, I know that's a bad title. I couldn't think of anything short enough. ...
I wrote the following script to let me know when various parts of the network are down. It used to look like this before last weekend when I got over 500 emails about 1 host being down all weekend:
this is in the... (1 Reply)