Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 9th, 2001, 01:26 PM
ccbcreg ccbcreg is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 7 ccbcreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb this is a BASH question.........

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

Reply With Quote
  #2  
Old July 10th, 2001, 06:09 AM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
  #3  
Old July 10th, 2001, 11:24 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
That's pretty good bash for somebody that "isn't a shell scripter"
__________________
Jon Coulter
ledjon@ledjon.com

Reply With Quote
  #4  
Old July 10th, 2001, 12:30 PM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8

Reply With Quote
  #5  
Old July 10th, 2001, 02:26 PM
ccbcreg ccbcreg is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 7 ccbcreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking thanks so much

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


Reply With Quote
  #6  
Old July 10th, 2001, 03:08 PM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.......>

Reply With Quote
  #7  
Old July 10th, 2001, 03:28 PM
ccbcreg ccbcreg is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 7 ccbcreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb mr. swift

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

Reply With Quote
  #8  
Old July 11th, 2001, 02:25 AM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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.

Reply With Quote
  #9  
Old July 11th, 2001, 04:57 PM
ccbcreg ccbcreg is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 7 ccbcreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > this is a BASH question.........


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway