#77022 - 2003-10-08 10:08 PM
Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
We have a Citrix Farm, where we have to periodically clean up a User Profile.
Here is the code..
code:
CLS BREAK ON 'INPUT THE USERNAME - e.g. JDOE'? '>' GETS $name
$hm='\\SHARESERVER\Citrix_Homedir\'+$name $pr='\\SHARESERVER\Citrix_Profiles\'+$name
;clean the home dir IF EXIST($hm) DIRCLEAN($hm,'\'+$filename) ENDIF
;clean the profile IF EXIST($pr) DIRCLEAN($pr,'\'+$filename) ENDIF
;build an array $citarr='01 02 03 05 06 07 08 09'
FOR EACH $i IN Split($citarr) $srv='\\CITRIXSERVER'+$i+'\admin$$\profiles\' IF EXIST($srv) DIRCLEAN($srv,$name) ENDIF NEXT ? ?'Process is complete - press a key' GET $ FUNCTION DIRCLEAN($dir,$flspec) $filename = Dir($dir+$flspec+'.*') WHILE $filename <> '' AND $filename <> '.' AND $filename <> '..' AND @error = 0 ?$dir ?$filename $result = SetFileAttr($dir+$filename+'.*',128) SHELL '%COMSPEC% /C RD /S /Q '+chr(34)+$dir+$filename+chr(34) $filename = Dir() ; retrieve next file LOOP ENDFUNCTION
Kent [ 10. October 2003, 19:22: Message edited by: kdyer ]
|
|
Top
|
|
|
|
#77024 - 2003-10-10 12:40 AM
Re: Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
True so true.. Problem is that we use a couple of old "circa 1985" programs. The other thing is that this server farm will be going away too.
I did the exercise more or less to see if I could shrink down a rather large batch script that does the same thing..
Kent
|
|
Top
|
|
|
|
#77025 - 2003-10-10 07:22 PM
Re: Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Did some addtional clean up and testing. Works like a champ.
Kent
|
|
Top
|
|
|
|
#77026 - 2003-10-13 06:10 PM
Re: Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
While everything works great, I am having a bit an issue putting this into KiXCrypt.
Kent
|
|
Top
|
|
|
|
#77027 - 2003-10-13 07:03 PM
Re: Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Ok..
Trying to run this from a Network share and get the following: quote:
CHECKING Citrix Server for:\\CITRIX07\admin$\profiles\kdyer \\CITRIX07\admin$\profiles\ KDyer'\\ISERVER\IS\IS_apps\Software_Utilities\Batch\Utility' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory.
It works fine, but I guess I need to change the Working directory of the Shortcut to point to %WINDIR%\SYSTEM32 ?
Kent
|
|
Top
|
|
|
|
#77029 - 2003-10-13 08:51 PM
Re: Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
I know that.. You know that.. Just thinking about the 'end user.'
Kent
|
|
Top
|
|
|
|
#77030 - 2003-11-13 04:34 PM
Re: Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Trying to get this to repeat..
It only repeats once.
code:
CLS BREAK ON NAMEINPUT
?'Would you like to do the clean again? - Y/N' ?'>' GETS $response
IF $response='Y' NAMEINPUT ELSE LEAVE ENDIF
FUNCTION LEAVE() ? ?"Process is complete - press a key" GET $ QUIT ENDFUNCTION
FUNCTION NAMEINPUT() ?'INPUT THE USERNAME - e.g. JDOE' ?'>' GETS $name
$hm='\\shareserver\Citrix_Homedir\'+$name $pr='\\shareserver\Citrix_Profiles\'+$name
IF $name="" ?"No Input Found, try again" SLEEP 2 EXIT ENDIF SERVERS($hm,$pr,$name) ENDFUNCTION
FUNCTION SERVERS($hm,$pr,$name) ;clean the home dir IF EXIST($hm) ?'CHECKING Home Drive: '+$hm ;DIRCLEAN($hm,'\'+$filename) DIRCLEAN($hm) ENDIF
;clean the profile IF EXIST($pr) ?'CHECKING Profile: '+$pr ;DIRCLEAN($pr,'\'+$filename) DIRCLEAN($pr) ENDIF
; ;build an array ; ?"CHECKING Citrix Servers..." FOR EACH $i IN Split('01 02 03 05 06 07 08 09') $srv="\\CITRIX"+$i+"\admin$$\profiles\" ?"CHECKING Citrix Server for:" $srv+$name IF EXIST($srv) DIRCLEAN($srv,$name) ENDIF NEXT ENDFUNCTION FUNCTION DIRCLEAN($dir,OPTIONAL $flspec) IF $flspec $filename = Dir($dir+$flspec+'.*') ELSE $filename = Dir($dir+'\*.*') ENDIF WHILE $filename<>'' AND @error = 0 IF $flspec $result = SetFileAttr($dir+$filename,128) SHELL '%COMSPEC% /C RD /S /Q '+chr(34)+$dir+$filename+chr(34) ELSE IF Len($filename)>2 ?$dir+'\'+$filename $result = SetFileAttr($dir+'\'+$filename,128) DEL $dir+'\'+$filename IF @ERROR<>0 SHELL '%COMSPEC% /C RD /S /Q '+chr(34)+$dir+'\'+$filename+chr(34) ENDIF ENDIF ENDIF $filename = Dir() LOOP ENDFUNCTION
Thanks for any insights.
Kent
|
|
Top
|
|
|
|
#77032 - 2003-11-13 04:55 PM
Re: Citrix Clean up script
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
A couple of observations.
You have an "Exit" without a value - bad karma, expecially before an "EndIf" where it is nearly guaranteed not to work. Change to "Exit 0".
Use loop structures to simplify the logic:
code:
$sLogin=udfGetUserName() While $sLogin udfDoCleanUp($sLogin) $sLogin=udfGetUserName() Loop
Function udfGetUserName() "Enter user login, or null to exit: " GetS $udfGetUserName EndFunction
Function udfDoCleanUp($sLogin) "Performing clean-up for '"+$sLogin+"'"+@CRLF EndFunction
|
|
Top
|
|
|
|
#77033 - 2003-11-25 12:17 AM
Re: Citrix Clean up script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Here is the final code.. It was still not deleting files properly. Code:
CLS BREAK ON $sLogin=udfGetUserName() While $sLogin NAMEINPUT($sLogin) udfDoCleanUp($sLogin) $sLogin=udfGetUserName() Loop
Function udfGetUserName() ? ?'Enter user login, or nothing to exit: ' GetS $udfGetUserName EndFunction
Function udfDoCleanUp($sLogin) ? ?"Performing clean-up for '"+$sLogin+"'"+@CRLF EndFunction
FUNCTION LEAVE() ? ?"Process is complete - press a key" GET $ QUIT ENDFUNCTION
FUNCTION NAMEINPUT($name) ;?'INPUT THE USERNAME - e.g. JDOE' ;?'>' ;GETS $name
$hm='\\HOMEDRIVESERVER\Citrix_Homedir\'+$name $pr='\\HOMEDRIVESERVER\Citrix_Profiles\'+$name
;IF $name="" ; ?"No Input Found, try again" ; SLEEP 2 ; EXIT 0 ;ENDIF SERVERS($hm,$pr,$name) ENDFUNCTION
FUNCTION SERVERS($hm,$pr,$name) ;clean the home dir IF EXIST($hm) ?'CHECKING Home Drive: '+$hm ;DIRCLEAN($hm,'\'+$filename) DIRCLEAN($hm) ENDIF
;clean the profile IF EXIST($pr) ?'CHECKING Profile: '+$pr ;DIRCLEAN($pr,'\'+$filename) DIRCLEAN($pr) ENDIF
; ;build an array ; ?"CHECKING Citrix Servers..." FOR EACH $i IN Split('01 02 03 05 06 07 08 09') $srv="\\CITRIXSERVER"+$i+"\admin$$\profiles\" ?"CHECKING Citrix Server for:" $srv+$name IF EXIST($srv) DIRCLEAN($srv,$name) ENDIF NEXT ENDFUNCTION FUNCTION DIRCLEAN($dir,OPTIONAL $flspec) IF $flspec $filename = Dir($dir+$flspec+'.*') ELSE $filename = Dir($dir+'\*.*') ENDIF WHILE $filename<>'' AND @error = 0 IF $flspec $result = SetFileAttr($dir+$filename,128) SHELL '%COMSPEC% /C RD /S /Q '+chr(34)+$dir+$filename+chr(34) ELSE IF Len($filename)>2 ?$dir+'\'+$filename $result = SetFileAttr($dir+'\'+$filename,128) DEL $dir+'\'+$filename IF @ERROR<>0 SHELL '%COMSPEC% /C RD /S /Q '+chr(34)+$dir+'\'+$filename+chr(34) ENDIF ENDIF ENDIF $filename = Dir() LOOP ENDFUNCTION
Thanks,
Kent
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 987 anonymous users online.
|
|
|