diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-10-03 16:12:35 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-10-03 16:12:35 +0200 |
commit | c678c9d5d430842ef06f231a4c39b5165f30578a (patch) | |
tree | f1b2316723bc25775824656f735f19c8adbcab3f /smbrm | |
parent | 5ee090c1319a538007796f1c63e0dfb1c0ac0491 (diff) | |
download | bin-c678c9d5d430842ef06f231a4c39b5165f30578a.zip bin-c678c9d5d430842ef06f231a4c39b5165f30578a.tar.gz |
add smbrm
Diffstat (limited to 'smbrm')
-rwxr-xr-x | smbrm | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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 +} + |