Re: [Samba] HowTo clear a share using smbclient ?

2008-05-21 Thread Charlie
"find /full/path/to/directory -type f  -exec rm {} \;"  will delete
all files found below /full/path/to/directory without deleting pipes,
directories, etc.

"find /full/path/to/directory -exec rm {} \;" will blow out everything.

If you don't use an environment variable for the path you run no
risks.  Admittedly you can get in trouble with find /$FullPath because
some logic error introduced by a maintenance programmer in the future
could cause $FullPath to resolve to the empty string... you might use
one of these tricks:

#1 - bodge up a sandbox

#!/bin/bash
mkdir /tmp/safedir  2>/dev/null
if cd /tmp/safedir
  then
find $FullPath  -exec rm {} \;
else
   echo ERROR: Unable to clear $FullPath
fi

#2 - sanity check

#!/bin/bash
if [ -n "$FullPath"]
  then
  find $FullPath  -exec rm {} \;
else
  echo FATAL ERROR
  echo Moronic programming SNAFU
  echo variable FullPath is empty!
fi

As a general rule, never script file glob wildcards into bash (because
a big directory will make bash's globbing overrun the shell command
line length limitation of your OS) and always put appropriate  sanity
checks into path composition code to detect unset variables.

Hope that helped!
--Charlie


On Wed, May 14, 2008 at 9:15 PM, Michael Heydon <[EMAIL PROTECTED]> wrote:
> This seems a bit Rube Goldberg to me, you have direct access to the file
> system, why not use it?
>
> If you are really worried that rm -rf /full/path/to/directory might somehow
> morph into rm -rf / you could do something like:
> su nobody -c rm -rf /full/path/to/directory
> In the event that it did try to delete / it would be limited to files
> writable by "nobody".
>
> I understand being cautious around rm -rf especially when running as root,
> but I think testing and being careful are a better solution than using samba
> to limit access.
>
> Jon Wilson wrote:
>>
>> Good Evening,
>>
>> I was wondering if anyone knows how to clear a share on a server using
>> a command line interface ?
>>
>> Basically I have a [public] share that I would like cleared down every
>> night, I've worked out that
>>
>> smbclient //apps-srv/public -N -c "del *" >
>> /var/log/samba_public_delete.log 2>&1
>>
>> seems to go most of the way to doing what I want - however it doesn't
>> delete subdirectories. Is there any easy way to accomplish this ?
>>
>>
>> I prefer the idea of running this rather than a 'rm -rf' from the
>> command line as I can script this and as it's a public share the
>> possibility of deleting anything else is pretty minimal.
>> I've seen a few examples of wayward rm command in crons to be wary of
>> doing that !
>>
>> Any ideas how I could accomplish this ?
>>
>>
>> Many Thanks
>>
>> Jon
>>
>
>
> --
> To unsubscribe from this list go to the following URL and read the
> instructions:  https://lists.samba.org/mailman/listinfo/samba
>
-- 
To unsubscribe from this list go to the following URL and read the
instructions:  https://lists.samba.org/mailman/listinfo/samba


Re: [Samba] HowTo clear a share using smbclient ?

2008-05-14 Thread Michael Heydon
This seems a bit Rube Goldberg to me, you have direct access to the file 
system, why not use it?


If you are really worried that rm -rf /full/path/to/directory might 
somehow morph into rm -rf / you could do something like:

su nobody -c rm -rf /full/path/to/directory
In the event that it did try to delete / it would be limited to files 
writable by "nobody".


I understand being cautious around rm -rf especially when running as 
root, but I think testing and being careful are a better solution than 
using samba to limit access.


Jon Wilson wrote:

Good Evening,

I was wondering if anyone knows how to clear a share on a server using
a command line interface ?

Basically I have a [public] share that I would like cleared down every
night, I've worked out that

smbclient //apps-srv/public -N -c "del *" >
/var/log/samba_public_delete.log 2>&1

seems to go most of the way to doing what I want - however it doesn't
delete subdirectories. Is there any easy way to accomplish this ?


I prefer the idea of running this rather than a 'rm -rf' from the
command line as I can script this and as it's a public share the
possibility of deleting anything else is pretty minimal.
I've seen a few examples of wayward rm command in crons to be wary of
doing that !

Any ideas how I could accomplish this ?


Many Thanks

Jon
  



--
To unsubscribe from this list go to the following URL and read the
instructions:  https://lists.samba.org/mailman/listinfo/samba


[Samba] HowTo clear a share using smbclient ?

2008-05-14 Thread Jon Wilson
Good Evening,

I was wondering if anyone knows how to clear a share on a server using
a command line interface ?

Basically I have a [public] share that I would like cleared down every
night, I've worked out that

smbclient //apps-srv/public -N -c "del *" >
/var/log/samba_public_delete.log 2>&1

seems to go most of the way to doing what I want - however it doesn't
delete subdirectories. Is there any easy way to accomplish this ?


I prefer the idea of running this rather than a 'rm -rf' from the
command line as I can script this and as it's a public share the
possibility of deleting anything else is pretty minimal.
I've seen a few examples of wayward rm command in crons to be wary of
doing that !

Any ideas how I could accomplish this ?


Many Thanks

Jon
-- 
To unsubscribe from this list go to the following URL and read the
instructions:  https://lists.samba.org/mailman/listinfo/samba