Page 1 of 1 1
Topic Options
#77022 - 2003-10-08 10:08 PM Citrix Clean up script
Kdyer Offline
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 ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77023 - 2003-10-09 08:29 PM Re: Citrix Clean up script
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Good ol Roaming profiles eh? They're of the devil. Best thing we ever did was make everyone use the citrix NFuse web interface for application access. No more desktop settings to worry about.
Top
#77024 - 2003-10-10 12:40 AM Re: Citrix Clean up script
Kdyer Offline
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. [Wink] 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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77025 - 2003-10-10 07:22 PM Re: Citrix Clean up script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Did some addtional clean up and testing. Works like a champ. [Wink]

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77026 - 2003-10-13 06:10 PM Re: Citrix Clean up script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77027 - 2003-10-13 07:03 PM Re: Citrix Clean up script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77028 - 2003-10-13 08:49 PM Re: Citrix Clean up script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Just ignore it as it doesn't do any harm.
_________________________
There are two types of vessels, submarines and targets.

Top
#77029 - 2003-10-13 08:51 PM Re: Citrix Clean up script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I know that.. You know that.. Just thinking about the 'end user.'

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77030 - 2003-11-13 04:34 PM Re: Citrix Clean up script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77031 - 2003-11-13 04:42 PM Re: Citrix Clean up script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You're not looping back.
code:
CLS
BREAK ON
DO
NAMEINPUT()
?'Would you like to do the clean again? - Y/N'
?'>'
WHILE $response<>'y' or $response<>'n'
GET $response
LOOP
$response
UNTIL $response<>'Y'
LEAVE()

_________________________
There are two types of vessels, submarines and targets.

Top
#77032 - 2003-11-13 04:55 PM Re: Citrix Clean up script
Richard H. Administrator Offline
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 Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1003 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.063 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org