I have a bat file that starts a service, and it's scheduled in the Task Scheduler. I used the psexec command for that. I want to add another trigger based on the event, the event being completion of the "start the service" (aforementioned) to create a .txt file on a remote server or the local server whichever is possible.
By default a file created in c:\Windows\System32\ (Windows 10)
Set full path to file in a batch file, for example
echo > c:\temp\myfilename.txt
Or set the path in a "Start in (optional)" field on "Actions" tab of task properties in Task Scheduler.
Writing a text file out with a batch script is as easy as echo'ing it out.
echo > myfilename.txt
Related
I'm attempting to create a batch file that I can use with Task Manager in Windows 7 to copy users' local Google Earth file to a network location where it can be backed-up. It appears that the BAT is running just fine, but the task does not complete or stop once it's done & continues to show a status of "running".
Thanks in advanced for the suggestions!
COPY/Y "C:\Users\lena.domain\AppData\LocalLow\Google\GoogleEarth\myplaces.kml" "\\server\u-users\Lena\system backup\Google Earth" cmd.exe /C
Running your single line in a command prompt window results in error message: syntax error
Reason 1: There is no space between command COPY and option /Y.
Reason 2: There is cmd.exe /C appended at end of the line.
Use in your batch file the line:
COPY /Y "C:\Users\lena.domain\AppData\LocalLow\Google\GoogleEarth\myplaces.kml" "\\server\u-users\Lena\system backup\Google Earth"
And additionally make sure that this job is executed from task scheduler with credentials (account) which has the permission to write something on server. The local SYSTEM account often used for scheduled tasks has surely no permissions to access files on the server at all. It looks like the best account to use for this scheduled task is the user account of lena.domain. See also Configure a Scheduled Task Item (At least Windows 7)
I'm currently using APEX Data loader to download Raw files from Salesforce.
Using the command line I can download the data that I need by simply typing the command.
Now I need to schedule the task so I don't need to do it everyday.
I run the dataloader by typing in the following
C:/Program Files (x86)/salesforce.com/data loader/bin/process.bat C:/datadownload/
C:/datadownload contains the configuration file I need to connect to Salesforce.
How can I set this thing up with Task Scheduler?
Resolved By creating another batch file... CALLing the Process.bat and adding the location of the file
Create another batch file with the same command - note the double quotes - and schedule that batch file in task scheduler. When you've done that then launch the scheduled task manually (right click on the task) to test that it works. Provide credentials and an account if it is to run when you aren't logged in.
I added the call command in case you want to add any post-processing tasks to the batch file later.
#echo off
call "C:/Program Files (x86)/salesforce.com/data loader/bin/process.bat" C:/datadownload/
I don't generally write batches, but I currently have a batch that uses forfiles to copy my FLVs from one folder to another. When I run the batch manually it works every time, but from a scheduled task, it throws a (0x1) error.
forfiles -p "C:\Program Files\Adobe\Flash Media Server 4.5\applications\name\streams" -m *.flv -s -d -1 -c "cmd /c copy #file ^0x22C:\Program^ Files\Adobe\Flash^ Media^ Server^ 4.5\applications\name\output\"
Not sure what syntax the scheduled task doesn't like.
Update
Under my scheduled task, Actions I have the following:
Program/script: name.bat
Start in (optional): \\servername\file\to\batch
Hi might be this is helpful,
I also face the same issue.
Just set the startin path like:
Here start in path is the path of batch file:
like you have enter in program script:
"E:\program related files\demo.bat"
then in startin just pass:
E:\program related files & done!
When my Start in (optional): path was a UNC path, it wouldn't work. So I moved my batch on the server and everything worked correctly.
UNC in Windows Batch Files
forfiles with UNC path
On Server 2008 R2 when running the batch file under domain user credentials, with confirmed "log on as a batch job" security in the Local Security Policy>Local Settings>User Rights Assignment,
even then my batch (copying a log file to a network share) would not run as scheduled task, until I selected in tab General the option "Run with highest privileges" (default NOT checked!)
The option Run whether user is logged on or not was also selected, with radio-button, but I guess this is quite standard, when selecting to run the task using a domain user account.
For the tab Actions : specifying the entire batch file name including its path, directly in "Program/script:" works fine (with Server 2008 R2)
Using double quotes inside the batch file causes no problems.
See the screen shot bellow.
You need to change the user to system
Most common reason for such problems is permissions: scheduled tasks does NOT always run with your user credentials. If you want scheduled task to run as you you will have to set it up as you or alternative user.
Besides that I hope that your line of code is a content of your batch file, you are not trying to run this command directly. Or are you?
P.S. What are these ^0x22 and ^ doing in your code?
I know this is an old question, but just wanted to share some info.
The (0x01) error code can also refer to resources that are not found. Therefore:
all files/folders referd from within the batch file should be accessible to the user which account is being used to run that scheduled task;
pay attention when using network locations in combination with "Run whether user is logged on or not" option;
the above-mentioned option can be tricky to use because some resources may be available only after log on.
For .bat files to run inside your scheduled task, you need to specify your .bat file path inside the start option - despite the fact that your .bat file is at the same directory as your .exe. Also, I flagged it to run with highest privilege. After I have done those two things, the task suddenly takes off without any problem!
I have several batch files which set a log file path and start visual studio 2010 ordertests. When I execute a batch file from windows explorer it runs perfectly. The problem is that when I use the Windows Task Scheduler to run a batch file my orderedtest is not executed.
Sample Code:
:::
::: This batch kicks off the searchinlineset test set node.
:::
SetLogPath.vbs "\\spm08r2dw\ATPData\Webportal Test Results\"
%comspec% /c "call "%VS100COMNTOOLS%vsvars32.bat" & mstest /testcontainer:"%SmartUITestInstallPath%AUTs\Tests\DemoSuite\SearchInlineSet\SearchInlineSet.orderedtest"" /nologo /usestderr
OS: Windows 7/2008 r2
Task Scheduler Configuration Images:
General:
(source: vsoh.com)
Settings:
(source: vsoh.com)
Conditions:
(source: vsoh.com)
Edit Action:
(source: vsoh.com)
Edit Trigger:
(source: vsoh.com)
Navigate to the General Tab of the Scheduled Task and select "run with highest privleges". Change the user account to SYSTEM and use a command that allows authentication parameters to be passed in the code such as the PowerShell cmdlet Start-BitsTransfer.
Also, fill in the correct start in path or arguments as necessary under the edit actions tab. I use a .bat file to kick it off, so I fill in the start in box.
Workaround:
Navigate to the General Tab of the Scheduled Task and select "Run only when user is logged on". Now the scheduler will execute the .ordertest scheduled task. This of course requires the user to be logged on but atleast the .bat will execute on schedule.
Setting the permissions explicitly for the folder and the file to full control and giving the start in folder parameter as the path for the directory where the batch file fixed the issue for me.
Check out this link
http://social.technet.microsoft.com/Forums/en-US/winservermanager/thread/d47d116e-10b9-44f0-9a30-7406c86c2fbe/
I am currently writing a script that calls WinSCP, connects an SFTP session, transfers a group of files from a local server to a remote server, closes the connection, then moves the local file to an archive. An alternate acceptable solution would be to copy the file to archive and then delete it from the source directory.
The problem I am having is that I can get WinSCP to open, connect and transfer the files, but after that the commands are ignored and I am unable to automate the connection close, file move or copy and the deletion and closing of command prompt. What is the best way to do this?
My FTP.bat file that connects the session and calls the script -
"C:\Program Files\WinSCP\WinSCP.exe" /console /command "lcd d:\bofa_ftp\out" /script=script.txt savedsession#winscpname.com
My script file that puts the file and closes the connection -
option batch abort
option confirm off
option exclude script.txt
put *.txt
close
When I add any commands to either the bat or the script they are ignored.
Commands after close are definitely not ignored. Your problem might be that you are trying to put Windows commands to WinSCP script. Note that there are no commands in WinSCP to move local files.
Instead of trying using Winscp3, try with plink.exe.
Plink is the best option to transfer files from winscp3 to your local.By using scp command we can transfer file from winscp to local as well as one folder in to another folder in winscp.
scp username#atechguideserver1.com:/data/tmp/samplscp.txt username#atechguideserver2.com:/data/tmp/dir/tech
Please refer to: http://99students.com/move-files-in-unix/