Shell scripting array question
Hi, I made a little rsync script for log transfer.
Code:
SERVERS=(SERVER1 SERVER2 SERVER3) What am I doing wrong here :S |
You may want to check the Advanced Bash-Scripting Guide
|
Code:
for SERVICE in ${$SERVER_$SERVICE[@]} |
I have got a array of servers and for each servers an array of services. Im trying to iterate through them so I can make rsync backup for each one. Hope you understand
I tried Code:
for SERVER in ${SERVERS[@]} :( |
Nope, I don't really understand. What do you expect the value of ${SERVER}_${SERVICE} should be?
I try to guess at this point: you have an array which store the names of the servers ($SERVERS) and three arrays which store the name of the services for each server ($SERVER1_SERV, $SERVER2_SERV, $SERVER3_SERV). So you want to loop over the servers names (SERVER1 SERVER2 SERVER3) to get the corresponding services names, right? If this is the case, you have to use "indirect reference" to build the name of the three service variables and then loop over them: Code:
#!/bin/bash |
(Shrug...)
Why not use Perl? Or PHP? Ruby? Python? You just have so many languages at your beck-and-call on a Linux system... that it makes very little sense to me to wrestle with "bash." You specify the language in the #! "shebang" line, and no one's the wiser. Don't get me wrong: I've seen some amazing things being done with "bash," but to me it just always feels like, "well yes, I see that it works, but why bother?" |
All times are GMT -5. The time now is 11:29 AM. |