summaryrefslogtreecommitdiffstats
path: root/smbrm
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-10-03 16:12:35 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-10-03 16:12:35 +0200
commitc678c9d5d430842ef06f231a4c39b5165f30578a (patch)
treef1b2316723bc25775824656f735f19c8adbcab3f /smbrm
parent5ee090c1319a538007796f1c63e0dfb1c0ac0491 (diff)
downloadbin-c678c9d5d430842ef06f231a4c39b5165f30578a.zip
bin-c678c9d5d430842ef06f231a4c39b5165f30578a.tar.gz
add smbrm
Diffstat (limited to 'smbrm')
-rwxr-xr-xsmbrm23
1 files changed, 23 insertions, 0 deletions
diff --git a/smbrm b/smbrm
new file mode 100755
index 0000000..bd3a414
--- /dev/null
+++ b/smbrm
@@ -0,0 +1,23 @@
+#! /bin/bash
+
+function smb_rmfr() {
+ AUTH_FILE=$1
+ SHARE=$2
+ shift
+ shift
+ local SHARE_DIR=$@
+ local OUTFILE=$(mktemp)
+ # remove all files
+ smbclient $SHARE -D "$SHARE_DIR" --authentication-file="$AUTH_FILE" -c "rm *;" >/dev/null 2>&1
+ # list sub directories
+ smbclient $SHARE -D "$SHARE_DIR" --authentication-file="$AUTH_FILE" -c "ls;" >$OUTFILE 2>/dev/null
+ # keep only directory name
+ IFS=$'\n'
+ for dir in $(cat $OUTFILE | sed 's/^ //' | sed '/^\./d' | sed '/^\s/d' | sed '$ d' | sed 's/\s\+D\s\+0\s\+.*$//'); do
+ smb_rmfr "$AUTH_FILE" "$SHARE" "${1}/$dir"
+ done
+ # local DIR=$(echo "$SHARE_DIR" | sed -e 's/\//\\/g')
+ smbclient $SHARE --authentication-file="$AUTH_FILE" -c "rmdir \"$(echo "$SHARE_DIR" | sed -e 's/\//\\/g')\";" >/dev/null 2>&1
+ rm $OUTFILE
+}
+