[CentOS] how to do repetetive command in shell

Thu Oct 21 18:57:18 UTC 2010
John Kennedy <skebi69 at gmail.com>

Damn...I will get this right...Need more sleep...

for i in `ls -d /opt/* | cut -d/ -f3`
do
cp /opt/${i}/test/ /backup/${i}
done

I KNOW this one will work...If not, I quit!!!
John


On Thu, Oct 21, 2010 at 14:55, John Kennedy <skebi69 at gmail.com> wrote:

> Not quite right...
>
> for i in `ls -d /opt | cut -d/ -f2`
> do
> cp /opt/${i}/test/ /backup/${i}
> done
>
> Takes out the /opt/ from my first try...
> John
>
> On Thu, Oct 21, 2010 at 14:51, John Kennedy <skebi69 at gmail.com> wrote:
>
>> for i in `ls -d /opt`
>> do
>> cp /opt/${i}/test/ /backup/${i}
>> done
>>
>>
>> On Thu, Oct 21, 2010 at 14:45, Roland RoLaNd <r_o_l_a_n_d at hotmail.com>wrote:
>>
>>>  Dear all,
>>>
>>> i'm writing a certain script which does a specific task in a repetitive
>>> manner, i'm going to give a similar script with the same concept hope you
>>> could advise me to a better way:
>>>
>>>
>>> USER1="roland"
>>> USER2="dany"
>>> USER3="kevin"
>>>
>>>
>>> cp -r /opt/$USER1/test /backup/$USER1
>>> cp -r /opt/$USER2/test /backup/$USER2
>>>
>>>
>>> such a command would be repeated 832 times (this is just an example)
>>> so instead of copying the above line 832 times and appending that user's
>>> number in each "$USER"
>>>
>>> is there a way to do it in a  smarter way ?
>>>
>>>
>>> thanks,
>>>
>>> --Rolad
>>>
>>>
>>> _______________________________________________
>>> CentOS mailing list
>>> CentOS at centos.org
>>> http://lists.centos.org/mailman/listinfo/centos
>>>
>>>
>>
>>
>> --
>>  John Kennedy
>>
>>
>
>
> --
>  John Kennedy
>
>


-- 
 John Kennedy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.centos.org/pipermail/centos/attachments/20101021/2a589383/attachment-0004.html>