[dba-Tech] Bit of scripting help?

Jon Tydda jon.tydda at lonza.com
Tue Apr 28 04:51:44 CDT 2015


Thanks Jim, don't know why I didn't think of that before :-)


Jon

-----Original Message-----
From: dba-Tech [mailto:dba-tech-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence
Sent: Monday, April 27, 2015 11:43 PM
To: Discussion of Hardware and Software issues
Subject: Re: [dba-Tech] Bit of scripting help?

Hi Jon:

The following is a little batch file that I used to check whether a directory existed. If it did then a file was copied and if not a file was deleted, then it exited the command. I left the code, as it was, so you could observe how the command operand "exist" could be used.

if exist y:\nul (dir > c:\download\jtb\20120425\exist.txt) else (if exist c:\download\jtb\20120425\exist.txt (del c:\download\jtb\20120425\exist.txt))
exit

If you need more like how to create a directory with the current date just ask.

HTH
Jim

----- Original Message -----
From: "Jon Tydda" <jon.tydda at lonza.com>
To: "Dba-Tech (dba-tech at databaseadvisors.com)" <dba-tech at databaseadvisors.com>
Sent: Monday, April 27, 2015 8:44:14 AM
Subject: [dba-Tech] Bit of scripting help?

Hi all

I'm trying to automate a long and tedious process with some batch files, and I've hit a stumbling block.

Every month I have a list of users who have left, and after their accounts have been closed down, I need to remove their home folders from the server.

We have three locations where someone's folder could be; Home-S, Home-M and Home-L (small, medium and large).

I've got a script that runs through one of these folders and changes the ownership of the relevant username's files and folders, and then deletes the main folder, but if the username isn't in the Small folder (for example), it then starts changing permissions to another random user's files and folders. What I'd like it do to is to realise that the folder doesn't exist, and instead search the Medium (and then Large) folder, or skip it entirely.

Here's my code - what am I missing?

for /F %%f in (Dellist.txt) do (takeown /f \\SERVER\home-s\%%f /r /d y) for /F %%f in (Dellist.txt) do (icacls \\ SERVER\home-s\%%f /inheritance:r /grant administrators:F /t /c) for /F %%f in (Dellist.txt) do (takeown /f \\ SERVER\home-s\%%f\*.* /r /d y) for /F %%f in (Dellist.txt) do (icacls \\ SERVER\home-s\%%f\*.* /inheritance:r /grant administrators:F /t /c)

for /F %%f in (Dellist.txt) do (call cmd.exe /C "rd \\uksfs01\home$\home-s\%%f" /S)

Thanks


Jon

________________________________
This communication and its attachments, if any, may contain confidential and privileged information the use of which by other persons or entities than the intended recipient is prohibited. If you receive this transmission in error, please contact the sender immediately and delete the material from your system.
_______________________________________________
dba-Tech mailing list
dba-Tech at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-tech
Website: http://www.databaseadvisors.com _______________________________________________
dba-Tech mailing list
dba-Tech at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-tech
Website: http://www.databaseadvisors.com

________________________________
This communication and its attachments, if any, may contain confidential and privileged information the use of which by other persons or entities than the intended recipient is prohibited. If you receive this transmission in error, please contact the sender immediately and delete the material from your system.



More information about the dba-Tech mailing list