Rsync for Windows cannot run on Task Scheduler - windows

I have batch script stated below and I run it on Task scheduler (Windows 2008 R2). When it runs, the status of the task is still running and takes too long. I couldn't see any errors or even in history or any logs. I already set the correct owner and permission of the locations in windows. Any one can shed me some lights? Thanks!
SETLOCAL
SET CWRSYNCHOME=C:\scripts\CWRSYNC
SET CYGWIN=nontsec
SET HOME=%HOMEDRIVE%%HOMEPATH%
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
rsync -rltDuv --progress -e "ssh -i /cygdrive/c/scripts/id_rsa" /cygdrive/c/backup/ root#123.123.123.123:/path/to/backup/ > c:/scripts/logs.txt 2>&1

Related

Windows 10 Task Scheduler: Execute bash script without showing up cmd

I have a task on my computer downloading a daily backup from my server. Basically it's:
bash.exe -c "cd /mnt/d/server_backups && ./download_backup.sh"
This does work, however it always pops up the cmd window, which wouldn't actually bother me, if it wasn't because it interrupts whatever I'm doing (gaming, watching a movie, working) and just throws me to desktop.
Changing task to "Run whether user is logged or not" doesn't work because apparently windows session zero (whatever that is) can't initiate calls with bash.
Is there another way to either not show up the cmd window or doing it without the SO deciding on its own that I want to have it main focused and everything else minimized?
You could use a VBS script to launch bash without a cmd.exe window, as follow :
hidden_launcher.vbs
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run WScript.Arguments(0), 0
Set WinScriptHost = Nothing
Here, we run the 1st argument received, and 0 means start the program hidden.
Now set up your task in the task scheduler :
Program to launch : C:\Path\to\hidden_launcher.vbs
Arguments: "bash.exe -c 'cd /mnt/d/server_backups && ./download_backup.sh' "
This should do the trick !!
I suggest you can use WSL like wsl -e cd /mnt/d/server_backups && ./download_backup.sh

Windows Task Scheduler - Task Won't Die

I have a task scheduled to run daily that executes a .bat file and I have checked the options for ending the task after an hour and forcing it to stop if it does not end when requested to, but it runs indefinitely until I manually kill it. Any ideas? (I do not want to use pskill in my script). Script below:
sqlcmd -S MyServer -U username -P password _Q "BACKUP DATABASE x to y"
net use z: "\\server1\project"
cd C:\trial1
copy * "Z:\backups"
net use z: /delete
exit
Thanks to Hans Passant for the answer! See below:
Taking away 'net use' and just directly copying to the server cleared up some error that the task scheduler was getting stuck on.

Regarding -i option usage of psexec

I was successfully running psexec to open application on remote PC using the following command:
psexec -s -i 1 \\135.20.230.160 -u administrator -p force calc
But suddenly today I found that 'calc' is not opening in the remote machine. Instead it is just running on the process list in task manager.
After some experiments when I changed '-i 1' to '-i 2' I found it working again.
Can anyone explain why this happened and how can I decide that the session number needs to be changed?
I need to build automation script for different users, so this is important to resolve.
Thanks.
You can use tasklist to display all tasks and see what session they are currently running on under the session# section.
The Psexec -i is asking for the session you would like to use.
Therefore as users log in to the machine the session numbers can be anywhere from 0 and up. To find out use tasklist with and check a process you know is running and view its session number.

ps command in MKS Toolkit list nothing when run the batch file from Task Scheduler

I created a batch file as below:
set VAR1=VALUE1
start another_batch_file
sleep 10
ps -l |grep abc > foo.txt
another_batch_file would start several processes, I want to use ps to list some specific ones. This script works well when I run it from a cmd window, although if I create a task in Task Scheduler to call this script automatically the foo.txt will be empty.
I also tried to output the ps -l result to a file, it's also empty
ps & grep both from MKS toolkit.
Edit:
Per the comments, I have tried with the script similar to the following:
set VAR1=VALUE1
start another_batch_file
sleep 10
ps > foo.txt
tasklist > bar.txt
Now foo.txt is still empty, while bar.txt has normal output which contains all the processes' information.
Any one has a clue?
Edit 2:
I have the box "Run with highest privileges" checked and the the ps command works well now.
I have been using the same user account when run the script in a cmd window or by a scheduled task, although the ps exeutable file located in a mapped drive, I think this caused the script needs higher privileges to run
If it works at the prompt: task scheduler runs in the system account by default and has no access to network resources, and if your other batch file is trying to access them then it will not load.
A batch file isn't never in the process list. Batch files are executed by cmd.exe, so cmd.exe is in the list.
But you should be able to access it with ps, if you add a switch for displaying the parameters, too.
It's also possible with tasklist.
tasklist /FI "IMAGENAME eq cmd.exe" /V | grep another_batch_file
C:\Windows\system32\cmd.exe - another_batch_file.bat cmd.exe
1320 Console 1 3.132 K Unknown

Can't get appengine:devserver_stop to work on Windows 2012 server

On my Windows 2012 server, I can run "mvn appengine:devserver_start" without any problems. When I run "mvn appengine:devserver_stop", it says "Stopping the development server" then "BUILD SUCCESS" but the process remains running and I have to kill it manually. Can't seem to find much information on these two goals (they're still pretty new) so wondering if this is a known issue or if it's something on my server.
I've tried both from TeamCity and running from the command line directly (with and without admin privileges).
Hey you can stop it using command line prompt.
get the PID using command
C:\netstat -a -n -o
and stop the process by another command
C:\Taskkill /PID <2004> /F
Full description with output is here.

Resources