1752279 Members
4473 Online
108786 Solutions
New Discussion юеВ

Need command or script

 
SOLVED
Go to solution
Shivkumar
Super Advisor

Need command or script

Hi All,

I am looking out for script or commands for below.

I have some instances in a logs directory as follows:
/logs/a/b/c/d/xyz-instance-1/some.log
/logs/a/b/c/d/xyz-instance-2/some.log
/logs/a/b/c/d/xyz-instance-3/some.log
/logs/a/b/c/d/xyz-instance-4/some.log
/logs/a/b/c/d/xyz-instance-5/some.log


I want to copy above in /tmp/ direcotry having below path and names.

/tmp/some.log-xyz-instance-1
/tmp/some.log-xyz-instance-2
/tmp/some.log-xyz-instance-3
/tmp/some.log-xyz-instance-4
/tmp/some.log-xyz-instance-5

Can someone please suggest commands or script ?

Thanks,
Shiv
11 REPLIES 11
River Tarnell
Advisor

Re: Need command or script

Try this:

for file in /logs/a/b/c/d/*/some.log; do
cp "$file" \
"`echo "$file" | sed 's,/logs/a/b/c/d/\(.*\)/some.log,/tmp/some.log-\1,'`"
done
Shivkumar
Super Advisor

Re: Need command or script

When i executed after convering to my actual paths it says that some.log are identical.
River Tarnell
Advisor

Re: Need command or script

Can you show the actual command you used, with the real paths? I tested the command I gave, and it works for the sample path:

% find logs
logs
logs/a
logs/a/b
logs/a/b/c
logs/a/b/c/d
logs/a/b/c/d/instance-1
logs/a/b/c/d/instance-1/some.log
logs/a/b/c/d/instance-2
logs/a/b/c/d/instance-2/some.log
logs/a/b/c/d/instance-3
logs/a/b/c/d/instance-3/some.log
logs/a/b/c/d/instance-4
logs/a/b/c/d/instance-4/some.log
% ls tmp
% for file in logs/a/b/c/d/*/some.log; do
cp "$file" \
"`echo "$file" | sed 's,logs/a/b/c/d/\(.*\)/some.log,tmp/some.log-\1,'`"
done
% find tmp
tmp
tmp/some.log-instance-1
tmp/some.log-instance-2
tmp/some.log-instance-3
tmp/some.log-instance-4
%
Steven Schweda
Honored Contributor

Re: Need command or script

> When i executed after convering to my
> actual paths [...]

If you can't figure out how to adapt a
suggestion to your actual data, and you
expect someone else to do your _whole_ job
for you, then it might make some sense to
provide the actual data. Or was your goal to
waste everyone's time?
Shivkumar
Super Advisor

Re: Need command or script

Steven,

You have not provided any input then how you have wasted your time ?

I have been posting my questions on this forum for almost 5 years and no one raised concern so far.

If anyone do not have time to answer then it is fine.

If i have been very good in sed and awk then i would have never posted my question here.

Please do not post your answer for my question if you feel i am wasting your time.


Thanks.
Shivkumar
Super Advisor

Re: Need command or script

Thanks River!! It worked. There was a typo as i had put extra "/" before /logs.

Steven Schweda
Honored Contributor

Re: Need command or script

> You have not provided any input [...]

Your (second) problem description did not
show what you did, nor the data you fed into
it. This makes it hard for someone with my
weak psychic powers to contribute much.

> [...] how you have wasted your time ?

Did I say that only _my_ time was wasted?

> Can you show the actual command you used,
> with the real paths? [...]

That looks to me like some wasted time.

As I said, "it might make some sense to
provide the actual data." Do you think that
not showing your actual commands and not
showing your actual data were helpful?
Shivkumar
Super Advisor

Re: Need command or script

These are production servers and i can't disclose any actual paths. That was the reason i had to convert the paths.


James R. Ferguson
Acclaimed Contributor
Solution

Re: Need command or script

Hi Shiv:

> These are production servers and i can't disclose any actual paths

I seriously doubt that this will compromise anything. What does it matter if I know the name of a path on a server if I can't get to the server in the first place?

Providing actual commands and actual filenames together with the actual error or warning message you received would help you solve your objective much faster.

Regards!

...JRF...