Take the 2-minute tour ×

I'm trying to write a shell script to backup websites, I've got it to go through each directory in vhosts and create a new directory vhosts/{siteurl}/private/backups/ and gzip up the site into there.

However, I also want it to read a file from private that will contain database name, user and password. So I can then use these to perform a mysqldump to private/backups/.

The problem is that I've never written a shell script before so I've go no idea how to read variable data into my script, or how I should format the file to be read.

Hope that's enough information.

share|improve this question
Would you like it to be bash, python or ...? Do you have any preference? –  pajton May 10 '10 at 15:08
add comment

1 Answer

up vote 1 down vote accepted

If the file is in name=value format and you're running bash or sh then you can use . to read and execute the contents of the file.




. ./vars.txt
echo "$foo * $bar"
share|improve this answer
if i put a command such as find . -type f -mtime +30 -exec rm -f {} \; into vars.txt would it also be executed? –  ianbarker May 17 '10 at 9:26
That is correct, as would exit which would promptly close the shell. –  Ignacio Vazquez-Abrams May 17 '10 at 11:13
thank you, that's great –  ianbarker May 17 '10 at 12:11
add comment

Your Answer


