|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
i need help.......
i am trying to get the contents of the following command into an array....... but i get the following error ./list_db.sh: db_array[0]=tcr_lease: command not found ./list_db.sh: db_array[1]=tcr_wo: command not found ./list_db.sh: db_array[2]=test: command not found i have read everything i could about arrays and i believe i am doing everything right. below is my code. Thanks in advance. It is not letting me add to the array..... i have tried different variable names too #!/bin/bash declare -a db_array t=0 for i in $( /usr/local/mysql/bin/mysqlshow -uroot -pXXXXXX ); do if [ $i != "|" ] then if [ $i != "Databases" ] then if [ $i != "+---------------------+" ] then db_array[$t]="$i" t=`expr $t + 1` fi fi fi done |
|
#2
|
||||
|
||||
|
Hi,
I am not a shell scripter but this works: Code:
#!/bin/bash
declare -a db_array
t=0
for i in $( /usr/local/mysql/bin/mysqlshow -uroot -pXYZ ); do
if [ `echo $i | grep -v "Databases" | egrep "^[a-zA-Z0-9]"` ]; then
db_array[$t]=${i};
echo "db_array[${t}] = [${db_array[$t]}]";
t=`expr $t + 1`;
fi
done
echo "Found ${#db_array[*]} databases";
given that you posted in the perl forum, why not use perl instead? much easier: Code:
#!/usr/bin/perl -w use strict; use DBI; my ($driver) = "mysql"; my (@mds) = DBI->data_sources($driver) or die "i'm melting!"; hope this helps.
__________________
Robert. |
|
#3
|
|||
|
|||
|
That's pretty good bash for somebody that "isn't a shell scripter"
![]()
__________________
Jon Coulter ledjon@ledjon.com |
|
#4
|
||||
|
||||
![]() |
|
#5
|
|||
|
|||
|
I got the foloowing error when i used your example:
declare: unknown option: `-a' ./list_db2.sh: db_array[0]=alex30: command not found ./list_db2.sh: db_array[${t}] = [${db_array[$t]}]: bad substitution ./list_db2.sh: Found ${#db_array[*]} databases: bad substitution unfortunately i haven't a clue what i am doing wrong. i may have a bad version of bash or sumthing. it works fine at home with FreeBSD but not on the production Linux machines. i built the same thing in php but with larger databases the php script will time out unless i change the php.ini file. any help would be greatly appreciated. i am looking into the Perl alternative. Thanks to you ![]() |
|
#6
|
||||
|
||||
|
Hmm...
what platform are you running on? I'm using RedHat Linux 7.0.Try the same thing as a C shell script: Code:
#!/bin/tcsh
set db_array
foreach i ( `/usr/local/mysql/bin/mysqlshow -uroot -p16mYsql!` )
echo ${i} | grep -v "Databases" | egrep "^[a-zA-Z0-9]"
if ( $status == 0 ) set db_array = (${db_array} ${i}) endif
end
echo "Found ${#db_array} databases [${db_array}]"
again, RedHat 7.0 so if this doesn't work let me have all the details and perhaps a copy of the script? Mail me anytime. Robert. <added after the event in a flash of perspiration> In the imortal words of Homer Simpson... Doh! Check your bash file, it probably a symbolic or hard link to something else. </added.......> |
|
#7
|
|||
|
|||
|
ok i am using Linux 2.2.14C11 Cobalt. I know..... its a cobalt.
That may be why its not working. bash -version == GNU bash, version 1.14.7(1) both of your examples work on FreeBSD 3.4 using bash -version == GNU bash, version 2.03.0(1)-release (i386--freebsd3.4) do you think i am running a "f__ked up old" version of bash... ?? You have all of the script that i have written since i haven't gotten very far into to it. drop all the databases (not mysql =) )on one machine and push the databases from the production machine to a backup... and run it as a cron. currently i am doing everything as sql textfiles.. but i have encryted data and this is useless as a text fill because you can't import it. soooo... i have had luck streaming it with mysqldump. security is not a big concern. thanks for the tcsh too... your opening my eyes |
|
#8
|
||||
|
||||
|
howdy,
FYI my bash version is: GNU bash, version 2.04.11(1)-release (i386-redhat-linux-gnu) I have no experience with v 1.14 but it sounds *really* old to me, my not have supported arrays in the same way or even at all. Glad to help with the scripting stuff. Drop me a line if you have any other questions. Robert. BTW When I was learning shell scripting the O'Reilly book was my favourite. Someone at my last job "borrowed" it and never gave it back but check out this book i am sure it will be useful. |
|
#9
|
|||
|
|||
|
thanks again.....
Mr. Swift,
I am indeed going to purchase that O'Reilly book. Seems likeyou have to have it. I am thinking that the version of BASH i have is old. I installed the newest version and everything is a go. Thanks again, ccbcreg ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > this is a BASH question......... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|