I always wonder how to assign multiple variables in for loop. Suppose I want to change the IP address of some users listed.
[root@server4 ~]# cat test1
user1
user2
user3
user4
user5
[root@server4 ~]# cat test1
user1
user2
user3
user4
user5
[root@server4 ~]# cat test2
190.10.20.1
20.1.1.2
30.12.13.13
13.23.23.12
32.12.12.1
test1 are my users and test2 contains IP address that I want to assign
[root@server4 ~]# xargs < test1
user1 user2 user3 user4 user5
[root@server4 ~]# xargs < test2
190.10.20.1 20.1.1.2 30.12.13.13 13.23.23.12 32.12.12.1
Now I am going define array
[root@server4 ~]# a=(user1 user2 user3 user4 user5)
[root@server4 ~]# b=(190.10.20.1 20.1.1.2 30.12.13.13 13.23.23.12 32.12.12.1)
[root@server4 ~]# c=${#a[@]} #length of array
Lets see if it works
[root@server4 ~]# for ((i=0;i<c;i++));do echo "${a[i]} ${b[i]}"; done
user1 190.10.20.1
user2 20.1.1.2
user3 30.12.13.13
user4 13.23.23.12
user5 32.12.12.1
what if we implement this in
[root@server4 ~]# for ((i=0;i<c;i++));do /usr/local/cpanel/bin/setsiteip ${a[i]} ${b[i]};done
let me test and will let you know. Please let me know if you have any other simple shortcuts.
Waiting got your results.
ReplyDelete