Bash Quoting Trouble
Gerade hab ich mir mal wieder die Haare gerauft ob der Bash Quoting und Escaping Rules. Ich möchte in einem Skript eine Datei per smbclient kopieren (warum ist smbclient eigentlich so sperrig?) und dabei die Verzeichnisse hüben wie drüben und den Dateinamen variabel festlegen. Das richtige quoting zu finden hat mich viel nerven gekostet aber hier ist eine Lösung die funktioniert
#!/bin/bash
#set -x # this has been very helpful in debugging the quoting
umask 022
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
# copy target settings
REMOTE_BACKUP_DIR=backup
REMOTE_NAS_ADDRESS=1.2.3.4
REMOTE_NAS_SHARE=BACKUP
# source dir and file
BACKUP_DIR=/srv/backup/project
TODAY=`date +'%Y%m%d%H%M%S'`
BACKUP_FILE=db_bak_$TODAY.bz2
# create the file to copy
...
SMB_CMD="cd $REMOTE_BACKUP_DIR; lcd $BACKUP_DIR; put db_bak_$TODAY.bz2"
smbclient -A /root/smbauth.conf -c "$SMB_CMD" //$REMOTE_NAS_ADDRESS/$REMOTE_NAS_SHARE
exit 0
Posted at 12:23PM Aug 13, 2009 by joerg in Allgemein | Kommentare[0]