How to read a configuration file in the same directory as the shell script in a Linux shell script

Source: Internet
Author: User

The configuration file is as follows

######### #BACKUP MYSQL config####### #database namedb_name=testdb_user=rootdb_pass=123456#### #backup Day Configbegin # # # # #day_backupdir =/home/backup/db/dayday_backup_fix=dayday_interval=1#### #backup Day Configend ############ Backup Week Configbegin # #week_backupdir =/home/backup/db/weekweek_backup_fix=weekweek_interval=2#### #backup Week configend ########### #backup month config begin # # # #month_backupdir =/home/backup/db/monthmonth_backup_fix= monthmonth_interval=3#### #backup Month config end #######

Name is: db_config

The shell script is as follows:

#!/bin/bash# name:bak_ftp_day.sh# this is a shellscript for auto file  backup and delete old backup# #DIR变量为当前shell脚本的目录DIR = "$ ( cd " $ (  dirname  "${bash_source[0]}"   " && pwd )" #使用source命令导入平级目录下的配置文件, Once introduced, the values in the file can be obtained directly from the variable names in the configuration source  $DIR "/" Db_configtime=_ '  date +%Y_%m_%d_%H_%M_%S  ' _echo   "------bakup---<<<--' date +%y-%m-%d-%h-%m-%s '----BEGIN--->>>---";echo  $day _ backupdir/$db _name$time$day_backup_fix.sql.gz "---is --begin---";mysqldump -u  $db _user -p$ db_pass  $db _name | gzip >  $day _backupdir/$db _name$time$day_backup_fix.sql.gzecho   $day _backupdir/$db _name$time$day_backup_fix.sql.gz "---is --finsh---";find  $day _backupdir  -name  $db _name "*.sql.gz"  -type f -mmin + $day _INTERVAL&NBSP;-EXEC&NBSP;RM&NBSP;-RF  {} \; > /dev/null 2>&1echo  "------bakup----<<<---' date +%y-%m-%d-%h-%m-%s '----finsh--->> >---";echo " ";



How to read a configuration file in the same directory as the shell script in a Linux shell script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.