penguin/utils

my env utils

commit 1bbc562fce83ce011c59849e9ad74fe2b694ea84

author斟酌 鵬兄 <tgckpg@gmail.com>
date2014-04-20T15:22:07Z
subjectSourced config.sh
commit 1bbc562fce83ce011c59849e9ad74fe2b694ea84
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2014-04-20T15:22:07Z

    Sourced config.sh
---
 .gitignore                |  2 ++
 bash/cronbackup/backup.sh | 17 +++++++++--------
 bash/cronbackup/config.sh |  7 +++++++
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4ef2717
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+
+*.log
diff --git a/bash/cronbackup/backup.sh b/bash/cronbackup/backup.sh
index a50cbd4..ea6bd05 100644
--- a/bash/cronbackup/backup.sh
+++ b/bash/cronbackup/backup.sh
@@ -1,18 +1,17 @@
 #!/bin/bash
 
-# IO Redirection
-exec > backup.log
+source ./config.sh
 
-# exec 2> backup_err.log
+# IO Redirection
+exec > $LOGFILE
 
-BMOUNT=/mnt/backup
-BAKDIR=$BMOUNT/backup/cron
+exec 2> $ERRLOG 
 
-if ! grep -qs $BMOUNT /proc/mounts; then
+if [[ -n $BMOUNT ]] && ! grep -qs $BMOUNT /proc/mounts; then
 	echo Mounting $BMOUNT ...
 	mount $BMOUNT
+    MOUNTED=$?
 fi
-	
 
 if ! [ -d $BAKDIR ]; then
 	mkdir $BAKDIR
@@ -86,4 +85,6 @@ while read line; do
 	# echo --\> $line
 done < backup_list
 
-umount $BMOUNT
+if [[ "$MOUNTED" -eq 0 ]]; then
+    umount $BMOUNT
+fi
diff --git a/bash/cronbackup/config.sh b/bash/cronbackup/config.sh
new file mode 100644
index 0000000..319ecee
--- /dev/null
+++ b/bash/cronbackup/config.sh
@@ -0,0 +1,7 @@
+#!/bin/bash`
+
+LOGFILE=backup.log
+ERRLOG=backup_errors.log
+
+BMOUNT=/mnt/backup
+BAKDIR=$BMOUNT/backup/cron