Need smart script !


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need smart script !
# 1  
Old 06-07-2012
Question Need smart script !

Hi,

I need a script to assign variables the below paths

Code:
 
/appl/user_projects/domains/<xxx>/servers/<yyy>/logs

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.
# 2  
Old 06-07-2012
can you give an example ? for exa our directorys
Code:
/appl/user_projects/domains/test.com/servers/dc1/logs
/appl/user_projects/domains/test.com/servers/dc2/logs
/appl/user_projects/domains/test.com/servers/dc3/logs

and
Code:
a1=test.com
b1=dc1
c1=dc2
......

like this ?
# 3  
Old 06-07-2012
Question

No... not like this.

I need this

Code:
/appl/user_projects/domains/test.com/servers/dc1/logs
/appl/user_projects/domains/test.com/config/dc6/logs
/appl/user_projects/domains/test.com/servers/dc2/logs
/appl/user_projects/domains/test.com/servers/dc3/dump

Now,

Code:
 
/appl/user_projects/domains/test.com/config/dc6/logs [does not have the "server" folder]

and

Code:
 
/appl/user_projects/domains/test.com/servers/dc3/dump [does not have a "logs" folder]

Hence both of them should be ignored.

This is what i need

Code:
 
a1=/appl/user_projects/domains/test.com/servers/dc1/logs
b1=/appl/user_projects/domains/test.com/servers/dc2/logs

Also, I need

Code:
dir1=dc1
dir2=dc2

# 4  
Old 06-07-2012
Wrench

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
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the difference between the commands cd ~smart and cd ~/smart

Is it possible for both commands to work? (1 Reply)
Discussion started by: phunkypants
1 Replies

2. Shell Programming and Scripting

Smart Backup Script

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)
Discussion started by: TheGacko
2 Replies

3. Shell Programming and Scripting

smart script?

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)
Discussion started by: raidzero
1 Replies

4. UNIX for Advanced & Expert Users

smart question

eg. : there is a file - 322 bytes, how can I (or you) view just a half of file (161 bytes)? (3 Replies)
Discussion started by: zylwyz
3 Replies
Login or Register to Ask a Question