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
On Oct 21, 2010, at 2:50 PM, Pintér Tibor wrote:
USER1="roland" USER2="dany" USER3="kevin"
cp -r /opt/$USER1/test /backup/$USER1 cp -r /opt/$USER2/test /backup/$USER2
$ for user in one two three four; do echo $user; done one two three four
or if the list of users is in a file, one per line
$ cat file roland dany kevin $ $ cat file | while read name do something $name done
Tony
On 10/21/10 11:45 AM, Roland RoLaNd 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:
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@hotmail.comwrote:
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@centos.org http://lists.centos.org/mailman/listinfo/centos
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@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@hotmail.comwrote:
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@centos.org http://lists.centos.org/mailman/listinfo/centos
-- John Kennedy
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@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@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@hotmail.comwrote:
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@centos.org http://lists.centos.org/mailman/listinfo/centos
-- John Kennedy
-- John Kennedy
On Thu, 21 Oct 2010, John Kennedy wrote:
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
Using ls in a for loop is rarely necessary.
for i in /opt/*; do cp -a ${i}/test /backup/$(basename $i) done
More simply, just cd to /opt before globbing filenames:
cd /opt for d in *; do cp -a ${i}/test /backup/${i} done
Roland RoLaNd wrote:
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
<snip> Guy, if you're a real sysadmin, and not just doing this at home, you *really* need to take a basic programming course. The first week or two would have told you about what are called "control structures".
mark
On 21 October 2010 19:45, Roland RoLaNd r_o_l_a_n_d@hotmail.com wrote:
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:
Good old Advanced Bash Scripting Guide comes to help!
http://tldp.org/LDP/abs/html/loops.html