w32tm /monitor VS w32tm /monitor /computers: - windows-xp

Let's say I have a computer called...StpdPrblm. When I open a command prompt window (domain user, local administrator) and run "w32tm /monitor" I get a good response from all 70 of my domain controllers. But when I run "w32tm /monitor /computers:StpdPrblm.domain.corp", I get the following output:
StpdPrblm.domain.corp [error 0x8007277C]
I get the same response from StpdPrblm no matter how many computers I try to query using the /computers: flag. What's going on? Googling that error code was fantastically unhelpful.
edit: StpdPrblm is XP SP 3.

Opened command prompt and ran:
net time /setsntp:domain_name
And then rebooting seems to have fixed it. Alternatively, the following can be executed to retstart the time service:
net stop w32time
net start w32time

net stop w32time
w32tm /config /syncfromflags:manual /manualpeerlist:"0.it.pool.ntp.org 1.it.pool.ntp.org 2.it.pool.ntp.org 3.it.pool.ntp.org"
net start w32time
w32tm /config /update
w32tm /resync /rediscover
.BAT Sample File :https://gist.github.com/thedom85/dbeb58627adfb3d5c3af
I also recommend this program :http://www.timesynctool.com/

Related

Start a Windows web server in the background with Ansible

I am looking to start a Go web server (a single .exe) on Windows Server via Ansible.
The equivalent in Linux that works great looks like:
- name: Start web server
become: true
become_user: root
shell:
cmd: nohup /home/centos/webserver </dev/null >/dev/null 2>&1 &
I can do it in PowerShell using Start-Process -FilePath -NoNewWindow .\webserver.exe but it terminates when I close the PowerShell window.
I have also looked into doing it with Start-Job { & C:\Path\to\webserver.exe } and Get-Job shows it completed, but not sure what that means since it's a web server and should just keep running until it's killed.
I need something that will star the webserver but not be tied to the shell so Ansible can do it via the win_shell module. I would have hoped this would work, but no luck:
- name: Start the webserver processes
win_shell: Start-Process -FilePath .\webserver.exe
args:
chdir: C:\Users\Administrator
Any and all suggestions much appreciated!
Looks like I was trying to find a more complicated way to do it with PowerShell when Ansible had built in functionality all along. This achieves exactly what I want:
- name: Start webserver
win_shell: .\webserver.exe
args:
chdir: C:\Users\Administrator
async: 180
poll: 0

Unable to start memcache on windows

I tried to starte memcache on windows 32 bit using the below command from cmd:-
D:\sw\memcache\memcached-1.4.5-x86\memcached-x86>memcached.exe -d
This is the error i am getting:-
Failed to ignore SIGHUP: Result too large
Has the command changed for starting 1.4.5 version?
I tried the below option also :-
B) Installation of memcached >= 1.4.5:
Extract the memcached windows binary to any directory.
In version 1.4.5 or later, memcached cannot run as a service. It must be started as a normal process using the task scheduler. To configure the memcached process to run automatically every time windows start, run a command prompt and type the following:
schtasks /create /sc onstart /tn memcached /tr "'c:\memcached\memcached.exe' -m 512"
Meanwhile, to remove the scheduled memcached task, run the following command:
schtasks /delete /tn memcached
But i am getting an access denied error message then. Do we need to give any special access rights for running memcahe.
Note:- I am totally new to memcache.
This command should be run as administrator. You have to right-click the command prompt and use the option to "Open as Administrator".
According to the information on this page:
https://commaster.net/content/installing-memcached-windows
version 1.4.5 or later can not be installed as a service. It must be installed as a Windows task.
To create this tasks via command line (or batch file), do in a manner similar to the example below:
CREATE TWO MEMCACHED TASKS
SCHTASKS /create /sc onstart /ru system /tn memcached1 /tr "C:\Xampp\memcached\memcached.exe -m64 -p11211"
SCHTASKS /create /sc onstart /ru system /tn memcached2 /tr "C:\Xampp\memcached\memcached.exe -m256 -p11212"
The tasks above will run on restart. Note the different amount of memory and port number, on every instance.
There are 2 ways to run the memcached on Windows:
Right click on the memcached.exe file and click on "Run as administrator", it will start the memcached.
Press "Window"+R, then type "cmd" and then press "Ctrl+Shift+Enter". It run it as administrator. Ten go to the lication of the file and use "memcached.exe -start" to run the memcached.
Hope this will help someone.

Renci SSH.NET - script hangs indefinitly

Here is the code - hangs after last command:
$DllPath = "Q:\A_FILES\PowerSHell\SSH_NET_for_powershell\Renci.SshNet_Binary\Renci.SshNet.dll"
[void][reflection.assembly]::LoadFrom( (Resolve-Path $DllPath) )
$SshClient = New-Object Renci.SshNet.SshClient('199.12.13.44', 22, 'userid', 'password')
$SshClient.Connect()
Get-Process | Out-File -FilePath D:\Powershell\SAN_NAP01_TEST.txt -Encoding ASCII
$SshCommand = $SshClient.RunCommand('statistics show-periodic')
The command issued via SSH above - STATISTICS show-periodic - when manually issued to an SSH session into the Netapp Storage SAN - starts displaying data and runs forever - you are not given a prompt again - you must manually issue CTRL-C to exit this command and then you receive the CLI prompt in the SSH session to issue another desired command. I assume this is why the powerscript hangs - because the command does not go back to a prompt - without a CTRL-C issued.
I would like to issue $SshCommand = $SshClient.RunCommand('CTRL-C') following the above last command (after a desired sleep time) - but the powershell script does not get control back.
Wondering if their is any way to get control back after the statistics... command and then be able to issue the CTRL-C command into the SSH session after a desired time interval.
are you connecting to a Netapp server?
If that's the case you could consider using the -iterations parameter in your command, so your statistics command returns.
$SshCommand = $SshClient.RunCommand('statistics show-periodic -iterations 5')

Starting XAMPP with batch only if it isn't already running

I am writing a batch for a new deployment of my company's software.. Here is what I have so far...
wscript.exe "invisible.vbs" "apache_start.bat" /wait
wscript.exe "invisible.vbs" "mysql_start.bat" /wait
"C:\Program Files\Internet Explorer\iexplore.exe" http://localhost
So as you can see, this script should start apache, then start mysql and then open the default page with IE.
The problem is if the user runs this script twice, it runs apache and mysql twice and loads two seperate instances. The solution I need is a way to check to see if the processes are already running and, if not, run the two wscript commands. I am absolutely horrible with shell, so please try to give specific responses! I am a software engineer, not a sysadmin. Thanks for the help!
As a software engineer I think you have a leg up on scripting over some sysadmins...
Using PowerShell would make this easy. Use the following template to execute the services - you'll need to use it twice, and follow up with launching IE as above.
If ((Get-Process mysqlprocessname.exe)) {Write-Host Skipping MySQL}
Else { Start-Process ...}
This is going to take a few minutes for you to research the best way of starting a process with PowerShell. Also, you might want to pipe Start-Process to Out-Null so the script waits to start IE and Apache.
Others may want to chime in with a simpler way from a batch file.
For XAMPP, there is a pv.exe file in the apache/bin folder that XAMPP uses to see if a service is running. Look at WorldDrknss' answer in this thread for some great info: http://www.apachefriends.org/f/viewtopic.php?p=80047
The code to solve your problem is to modify your mysql_start.bat file to this:
#echo off
apache\bin\pv mysqld.exe %1 >nul
if ERRORLEVEL 1 goto Process_NotFound
echo MySQL is running
goto END
:Process_NotFound
echo Process %1 is not running
mysql\bin\mysqld.exe --defaults-file=mysql\bin\my.ini --standalone --console
goto finish
:finish
That will check if mysqld.exe is running. If it is, it just echos that out. If not, it starts the service.

Sleep command in batch file?

When I'm writing a batch file to run automatically, how do I write it so that when the batch file is run, it can pause for a couple seconds in between commands?
Context:
psexec \\server -u user -p pass cmd
[there needs to be a pause here for psexec to establish a connection]
dir /s >output.txt \\server\shared
*Note: the reason I run the dir command server-side using psexec and not locally is because it's much faster to run dir on a local machine than remotely, and time is of the essence.
When I'm doing this by hand it's obviously easy, I just wait. But running a batch file makes it run all commands at near instant speeds next to each other, regardless of the completion status of the last command. How do I put in a pause?
On Windows Vista / Windows 7 you can use the timeout command:
timeout /T [delay in seconds] /NOBREAK > NUL
On previous versions of Windows, you can use the ping command (the ping command has 1000 ms of delay between each iteration):
ping -n [delay in seconds + 1] 127.0.0.1 > NUL
Some versions of Windows (like Windows Server 2003) has the sleep.exe executable:
sleep [delay in seconds]
Note: Windows Resource kit for 2003 contains sleep.exe command.
If you don't know the Windows version, simply use the ping hack since it'll be available.
There is timeout command in more recent version of Windows:
timeout /T 10
Windows Resource kit for 2003 will install on Windows XP. It contains SLEEP.EXE which can be used from a command batch file.
download is here http://www.microsoft.com/download/en/details.aspx?id=17657
I think the information here: http://malektips.com/xp_dos_0002.html would explain it better than I.
There's still the case of error handling though (what if the remote machine isn't up?). cmd.exe is quite useless for doing any remote activities for the most part, using powershell would enable so much more.
EDIT::
In fact, you can execute a program stored locally with psexec (it gets copied across and executed locally server-side) - would using that be a more viable alternative?
Without knowing what commands you're intending to run it's hard to take it much further.
EDIT(2)::
If it's just the one command you're running, simply store it in a dedicated file, like 'remote_dir_listing.cmd', and then use psexec with:
psexec \\server -u <user> -p <pass> -c -f remote_dir_listing.cmd
This will force a copy of the local file to the remote side each time you execute it (in case you want to expand it). In this way, you bypass the need for a pause at all - only when psexec has got the pipes open will it run, and once it completes, it closes itself silently.