Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

solution for scheduled defrag on pcs in the list and shutdown after defrag

Posted on 2009-07-08
4
Medium Priority
?
359 Views
Last Modified: 2012-05-07
Currently I have three different script:

1. First script will send out the magic packet to wake pcs
2. Second script will run the defrag for all the pcs that are listed in the text file using psexec
    psexec @pc_list.txt -u administrator -p password -d -e defrag.exe c:
3. Finally using psshutdown from sysinteral to shut down pc listed int the text file.
    psshutdown -u administrator -p password -s -c @pc_list.txt

I am using windows scheduler to run the script at night.
I think the current script doing quite well and very simple to use. However when i think of improving the script, pcs should shut down right after defrag is finished.

Wondering if there is easy way to improve the script so the pcs shut down right after defrag is finish.

if i don't use psexec to do remotely following script should work but can't figure out how to use with psexec.

defrag c: -f
shutdown -s -t 10 -f -c "Shutdown after defrag"






0
Comment
Question by:monaye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 23

Expert Comment

by:rhandels
ID: 24806321
Hey,

I don't believe you can.. For as far as i know it is impossible to shut down the PC after the defrag using a defrag command line.
The other issue is that when you actually trigger the reboot from the same batch file as you trigger the defrag, you need to do some sort of timeout within the bacth script that shuts down the PC. This isn;t your biggest issue, creating a timeout.. The problem is that you cannot tell how long the defrag is going ot take before it ends..

As far as i can see the batch execution you set up is a very good solution..
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 1400 total points
ID: 24806349
The command below will defrag the remote machine and then shut down when it is finished.


psexec \\<computer> cmd /c defrag c: -f ^& shutdown -s -t 10 -f -c "Shutdown after defrag"

Open in new window

0
 
LVL 1

Author Comment

by:monaye
ID: 24809222
Thank you Shift-3,

It looks so simple after all.
All you are doing is psexec the cmd and passing the command?

It works perfect.

Do you happen to know how to output log to text file?
0
 
LVL 1

Expert Comment

by:Fritch84
ID: 25139787
Thanks very much for asking for this great little script command.  I'm just starting to use it now - working like a charm.

"Do you happen to know how to output log to text file?"

I'm sure if this is what you're after but if you add this to the end -' > c:\analysis.txt' - it will tell you the before analysis and then give you the defragmentation report.  The only problem with this is that the computer name is not listed next to the defrag report.  But at least it's a good confirmation that it's all working correctly.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question