Avatar of Sekar Chinnakannu
Sekar ChinnakannuFlag for Singapore

asked on 

Automated server reboot script, without affecting users in citrix.

I am looking for script to wait all users to log off from citrix server and once there are no users logged on, then the server will have to reboot itself. Please help me to get the script.
CitrixWindows Server 2003

Avatar of undefined
Last Comment
basraj
Avatar of basraj
basraj
Flag of India image

Check the last post with script. It waits until there are no active users:

http://www.dabcc.com/posts.aspx?thread=330&forum=67
Avatar of VishavSingh
VishavSingh
Flag of India image

This will disable the logins on the server and will give three messages to users before 7, 5 and 1 minute and then it will enable login and will initiate server reboot.  You can save below script with extension "xxxx.cmd" and put in server's schedule task to automate reboot.

Please find below batch script to reboot server and cleaning system.

ECHO OFF
CLS

:: === Variable Section =======================================================
SET mDate=%DATE%
SET mTime=%TIME%
SET mVersion=1.0

:: --- Set LOG FILE location and name -----------------------------------------
::     The LOG FILE is the same name as the CMD file with TXT extension
::     Initialize the LOG
SET mLogFileFolder=%SystemRoot%\Debug
FOR /F %%I IN ("%0") DO SET mLog=%mLogFileFolder%\%%~nI.txt
ECHO -------------------------------------------------------------------- >%mLog%

:: --- Profile and Temp Folders ---------------------------------
SET mProfDir="%SystemDrive%\Documents and Settings"
SET mTempDir=%SystemRoot%\Temp
SET mCTempDir=%SystemDrive%\Temp


:: --- Start of Script Section ------------------------------------------------
ECHO Automatic Server Reboot : Version: %mVersion%           >>%mLog%
ECHO -------------------------------------------------------------------- >>%mLog%
ECHO Server %Computername% has initiated a automatic restart sequence...  >>%mLog%
ECHO Date and Time : %mDate% @ %mTime%                                    >>%mLog%
ECHO.                                                                     >>%mLog%

ECHO ==================================================================== >>%mLog%
ECHO SCRIPT: Dump of Script Variables...                                  >>%mLog%
ECHO -------------------------------------------------------------------- >>%mLog%
ECHO Log File............: %mLog%                                         >>%mLog%
ECHO.                                                                     >>%mLog%

ECHO ==================================================================== >>%mLog%
ECHO LOGON: Disable logins to this server...                              >>%mLog%
ECHO -------------------------------------------------------------------- >>%mLog%
CHANGE LOGON /DISABLE

MSG * /TIME:30 This server will be rebooted in 7 minutes. Please save all work, close applications and log out. Other Servers will be available for Application Service...
ECHO - Pause script for 7 minutes to allow users to finish their work...  >>%mLog%
SLEEP 120

MSG * /TIME:30 This server will be rebooted in 5 minutes. Please save all work, close applications and log out. Other Servers will be available for Application Service...
ECHO - Pause script for 5 minutes to allow users to finish their work...  >>%mLog%
SLEEP 240

MSG * /TIME:30 This server will be rebooted in 1 minute. Please save all work, close applications and log out. Other Servers will be available for Application Service...
ECHO - Pause script for 1 minute to allow users to log out...             >>%mLog%
SLEEP 60

ECHO - Closing any active sessions...                                     >>%mLog%
QUERY session >%mLogFileFolder%\session.txt
ECHO.                                                                     >>%mLog%
TYPE %mLogFileFolder%\session.txt                                         >>%mLog%

FOR /F "skip=2 tokens=3," %%i in (%mLogFileFolder%\session.txt) DO LOGOFF %%i
SLEEP 15
DEL /F /Q %mLogFileFolder%\session.txt
ECHO.                                                                     >>%mLog%

GOTO :CONTINUE

:CONTINUE
ECHO ==================================================================== >>%mLog%
ECHO MAINT: Clean stuck Profiles...                                       >>%mLog%
ECHO -------------------------------------------------------------------- >>%mLog%
ECHO - Deletes Profiles except All Users, Default User, Administrator, AM Accounts and VScanServ... >>%mLog%
DIR %mProfDir% /AD /B |FIND /V /I "All Users" |FIND /V /I "LocalService" |FIND /V /I "NetworkService" |FIND /V /I "ddevsvc" |FIND /V /I "srvshedr" |FIND /V /I "Default User" |FIND /V /I "Administrator" |FIND /V /I "VScanServ" |FIND /V /I "osgvservice" |FIND /V /I "am" >%mLogFileFolder%\Profs.txt
FOR /F "tokens=1-6" %%a IN (%mLogFileFolder%\Profs.txt) DO CALL :DELPROFS %%a %%b %%c %%d %%e %%f
DEL /F /Q %mLogFileFolder%\Profs.txt
ECHO.                                                                     >>%mLog%

ECHO ==================================================================== >>%mLog%
ECHO MAINT: Clean Temp folder...                                        >>%mLog%
ECHO -------------------------------------------------------------------- >>%mLog%
DEL /F /Q /S "%mTempDir%\*.*" >>%mLog% 2>&1
DIR %mTempDir% /AD-H /B >%mLogFileFolder%\TempDir.txt
TYPE %mLogFileFolder%\TempDir.txt                                         >>%mLog%
FOR /F "tokens=1-6" %%a IN (%mLogFileFolder%\TempDir.txt) DO RD /S /Q "%mTempDir%\%%a"
SLEEP 15
DEL /F /Q %mLogFileFolder%\TempDir.txt
ECHO.                                                                     >>%mLog%

ECHO ==================================================================== >>%mLog%
ECHO MAINT: Clean Temp folder...                                        >>%mLog%
ECHO -------------------------------------------------------------------- >>%mLog%
DEL /F /Q /S "%mCTempDir%\*.*" >>%mLog% 2>&1
DIR %mCTempDir% /AD-H /B >%mLogFileFolder%\CTempDir.txt
TYPE %mLogFileFolder%\CTempDir.txt                                         >>%mLog%
FOR /F "tokens=1-6" %%a IN (%mLogFileFolder%\CTempDir.txt) DO RD /S /Q "%CTempDir%\%%a"
SLEEP 15
DEL /F /Q %mLogFileFolder%\CTempDir.txt
ECHO.  

:: --- Finishing...
ECHO ==================================================================== >>%mLog%
SET mDate=%DATE%
SET mTime=%TIME%
ECHO The server is shutting down for a reboot                             >>%mLog%
ECHO Date and Time : %mDate% @ %mTime%                                    >>%mLog%
ECHO.                                                                     >>%mLog%
ECHO End of Logfile ----------------------------------------------------- >>%mLog%

:FINISHED
CHANGE LOGON /Enable
TSSHUTDN 0 /reboot /delay:0
EXIT

:: --- Script Functions, keep at EOF ------------------------------------------
:DELPROFS
:: --- Delete Stuck Profiles
ECHO Trying to Delete %mProfDir%\"%*"                                     >>%mLog%
DEL /F /Q /S %mProfDir%\"%*" >>%mLog% 2>&1
RD /Q /S %mProfDir%\"%*" >>%mLog% 2>&1
GOTO :RETURN
:: --- end function

:: --- Use this to return to caller
:RETURN

Avatar of Sekar Chinnakannu

ASKER

Vishva, I dont want to send notification to users, we need to wait users to log off from citrix server and once there are no users logged on, then the server will have to reboot itself. We are not sure what exactly user doing. Some time uesr with customers in that case forcing user log off is not a good option.
Avatar of Sekar Chinnakannu

ASKER

Basraj, I tried the script which you suggested, after all the user logged no one logged in server didnt rebooted.

- Server disabled the login
- no users logged in
- only port listining is active, but server not rebooted.
- finally I logged to server console and restated the server then enabled same in xitrix server.

ENV - Windows 2003 Server, PS 4.5 & Xenapp.
ss.jpg
Avatar of Sekar Chinnakannu

ASKER

log.txt output

Tue 05/17/2011
Starting shutdown script
Aborted - Shutdown script timed out.
exited
Avatar of Sekar Chinnakannu

ASKER

Today I downloaded script from http://www.dabcc.com/miab/reboots/smartreboot.zip and tested, its working fine, but when users are working it sends the notification and restarted the server.

we need to wait users to log off from citrix server and once there are no users logged on, then the server will have to reboot itself. Please help me to get same in script
sc.jpg
ASKER CERTIFIED SOLUTION
Avatar of Carl Webster
Carl Webster
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of basraj
basraj
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Sekar Chinnakannu

ASKER

Thanks Carl & Basraj, will check and update.
Avatar of basraj
basraj
Flag of India image

Also check this Centinel tool which will reboot only after the users are off.

http://www.dabcc.com/downloadfile.aspx?id=271
Windows Server 2003
Windows Server 2003

Windows Server 2003 was based on Windows XP and was released in four editions: Web, Standard, Enterprise and Datacenter. It also had derivative versions for clusters, storage and Microsoft’s Small Business Server. Important upgrades included integrating Internet Information Services (IIS), improvements to Active Directory (AD) and Group Policy (GP), and the migration to Automated System Recovery (ASR).

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo