Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why script wont read data from file ?

Status
Not open for further replies.

JackTheRussel

Programmer
Joined
Aug 22, 2006
Messages
110
Location
FI
Hi all.

I have backup script which backup my database in every day.
Code:
#!/bin/sh

datetime=`date '+%y-%m-%d-%H-%M-%S'`
mysqldump -u root -pPassword database | gzip > /home/user/backups/backup-$datetime.sql.gz

And its works perfectly.

Now I would like to increase security and I wrote username and password information in file named security.ini
it locates in address /home/user/security.ini

seurity.ini
Code:
[DATABASE]
db_host= localhost
db_name=database
db_username=root
db_password=Password

How my script can read these informations ? I try like this, but
its not working.
Code:
#!/bin/sh

$security=`'/home/user/security.ini'`;
datetime=`date '+%y-%m-%d-%H-%M-%S'`

mysqldump -u $security{'DATABASE'}{'db_username'} -p$security{'DATABASE'}{'password'} database | gzip > /home/user/backups/backup-$datetime.sql.gz

I just get error: Got error: 1045: Access denied for user '{DATABASE}'@'localhost' (using password: YES) when trying to connect
 
wrong forum mate, this is the perl forum, you want the appropriate shell scripting forum.

- Kevin, perl coder unexceptional!
 
In shell it would be like this

Code:
security=`cat /path/to/file`;
echo "$security"

for Perl;
Code:
open FILE,"< /path/to/file" or warn "$!\n";
while (<FILE>) {
do what you need to do here;
}
close FILE;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top