I need to schedule a task in Windows Server 2003 that executes this script that deletes files older that n days in the specified folder. The script needs 3 parameters:
The script works fine if the first parameter has no spaces inside. This is an example of parameters that work:
This is an example that does not work:
This does not work too:
I think it would be a quotes problem but I can't figure out the solution. I'd like not to insert values directly into the script if possible
Thank you all for help
3 Answers
Not a full solution, but a workaround that might get your task working until you find a better resolution: you could try calling a batch file that does not take parameters and does nothing but call 'C:Program FilesSCRIPTDeleteFilesOlderThanXDays.cmd' 'N:Program FilesLOG' *.zip 60
Thank you for your answers. After further investigations it comes out that the batch file should be modified adding quotes around @path to allow spaces:
@echo off forfiles -p %1 -s -m %2 -d -%3 -c 'cmd /c del /q '@path'
The path parameter has to be quoted too as follows because of spaces:
'C:Program FilesSCRIPTDeleteFilesOlderThanXDays.cmd' 'N:Program FilesLOG' *.zip 60
Now, it does not work too because having 'C:Program FilesSCRIPTDeleteFilesOlderThanXDays.cmd' followed by a quoted parameter fails with an error like 'C:Program is not recognized as an internal or external command..' so no luck again.
Workaround that works:
'C:Program FilesSCRIPTDeleteFilesOlderThanXDays.cmd' . *.zip 60 Kanchana telugu movie horror ringtones free download.
Start in: 'N:Program FilesLOG'
In your batch file add quotes around the parameters that can include spaces.So, at least around %1.
Not the answer you're looking for? Browse other questions tagged windows-server-2003batch-filescheduled-task or ask your own question.
I am building a script that will do database backup and will copy the backup to a safe storage location on another computer. I have that specific location already mounted on Y: and have built my script (.bat).The script runs fine in test runs, but when task scheduler runs it the part in charge of copying:
doesn't run. In order to see what is going on when scheduler runs the script I appended
>> backup.log
to every line of the script.When I tried manually running the scrip through task scheduler in order to test what is the problem the only thing copy outputs is:
and nothing else. No other error.
I know that Start Folder set in task could be the problem but I did set it to the folder where the script is. Also start folder shouldn't be an issue since all the time I'm working with full paths.
EDIT: I'm running this on Windows Server 2003 SP2 if it has anything to do with it.
So any ideas what could be the problem?
3 Answers
can you try to map the network drive inside the script or use UNC ?something like
Hello I have recently done some work with Windows server Scheduled tasks.
The exit code may help you if you look at the task scheduler highlight your task and select the history tab 0x0 is success 0x1 is some kind of error but not very specific..
Some basic pointers
- You can test the scheduled task by right clicking and selecting run
- The user account the task is running as requires logon as batch userpermissions on the server you intend to run the task on this can beadded to local policy start> run/search gpedit.msc or byadministering group policy on the domain.
- If it is not the account you are using to test shift+right click command prompt and run as the user running the task then run your batch file this will at least give you confidence the user account can run the batch file interactively
for more information see http://technet.microsoft.com/en-us/library/cc721846.aspx
I was having this issue when trying to access/copy files from a protected network share via a Scheduled Task.
My problem was with the Scheduled Task's configuration. Using Win10, my Task was configured as follows (under 'General' - 'Security options'):
- [ ] 'Run only when user is logged on'
- [x] 'Run whether user is logged on or not'
- [x] 'Do not store password. The task will only have access to local resources' [This is the problem]
I fixed the problem by un-checking the 'Do not store password' checkbox.Presumably, I could also fix it by opting for 'Run only when user is logged on'.
Not the answer you're looking for? Browse other questions tagged cmdcopyscheduled-tasksnetwork-drive or ask your own question.
Here’s a simple batch file script to backup the Windows Server 2003 System State to a removable drive:
Save the script as ssbackup.bat (or whatever name you choose). If you are running the script on a Windows 2000 server, change the path to ntbackup.exe to c:winntsystem32ntbackup.exe
You should modify the following items in the script:
server04 system state backup to I – This is the backup description.
I:server04server04-system-state-%dtt%.bkf– this is the path to save the backup file to and file name. My file is saved to the I:server04 directory.
I used ssgsergio’s script as my basis for the first part of the script – I never can remember the syntax for using the day-date-time variables (%dtt% in this case).
The inspiration for the second part of the script came from KB 239892, ntbackup help, and looking at the properties of backup I already had setup – you can see these details in Control Panel – Scheduled Tasks, assuming you have a backup already scheduled.
If you’d like explanations of what all the command line options for ntbackup.exe are, from a command prompt run:
The ntbackup syntax is:
Backup Batch File Example
Syntax
ntbackup backup [systemstate]“@FileName.bks” /J {“JobName“} [/P {“PoolName“}] [/G {“GUIDName“}] [/T { “TapeName“}] [/N {“MediaName“}] [/F {“FileName“}] [/D {“SetDescription“}] [/DS {“ServerName“}] [/IS {“ServerName“}] [/A] [/V:{yes | no}] [/R:{yes | no}] [/L:{f | s | n}] [/M {BackupType}] [/RS:{yes | no}] [/HC:{on | off}] [/SNAP:{on | off}]
Parameters
- systemstate
- Specifies that you want to back up the System State data. When you select this option, the backup type will be forced to normal or copy.
- @FileName.bks
- Specifies the name of the backup selection file (.bks file) to be used for this backup operation. The at (@) character must precede the name of the backup selection file. A backup selection file contains information on the files and folders you have selected for backup. You have to create the file using the graphical user interface (GUI) version of Backup.
- /J {“JobName“}
- Specifies the job name to be used in the backup report. The job name usually describes the files and folders you are backing up in the current backup job.
- /P {“PoolName“}
- Specifies the media pool from which you want to use media. This is usually a subpool of the Backup media pool, such as 4mm DDS. If you select this you cannot use the /A, /G, /F, or /T command-line options.
- /G {“GUIDName“}
- Overwrites or appends to this tape. Do not use this switch in conjunction with /P.
- /T {“TapeName“}
- Overwrites or appends to this tape. Do not use this switch in conjunction with /P.
- /N {“MediaName“}
- Specifies the new tape name. You must not use /A with this switch.
- /F {“FileName“}
- Logical disk path and file name. You must not use the following switches with this switch: /P /G /T.
- /D {“SetDescription“}
- Specifies a label for each backup set.
- /DS {“ServerName“}
- Backs up the directory service file for the specified Microsoft Exchange Server.
- /IS {“ServerName“}
- Backs up the Information Store file for the specified Microsoft Exchange Server.
- /A
- Performs an append operation. Either /G or /T must be used in conjunction with this switch. Do not use this switch in conjunction with /P.
- /V:{yes | no}
- Verifies the data after the backup is complete.
- /R:{yes | no}
- Restricts access to this tape to the owner or members of the Administrators group.
- /L:{f | s | n}
- Specifies the type of log file: f=full, s=summary, n=none (no log file is created).
- /M {BackupType}
- Specifies the backup type. It must be one of the following: normal, copy, differential, incremental, or daily.
- /RS:{yes | no}
- Backs up the migrated data files located in Remote Storage. The /RS command-line option is not required to back up the local Removable Storage database (that contains the Remote Storage placeholder files). When you backup the %systemroot% folder, Backup automatically backs up the Removable Storage database as well.
- /HC:{on | off}
- Uses hardware compression, if available, on the tape drive.
- /SNAP:{on | off}
- Specifies whether or not the backup should use a volume shadow copy.
- /M {BackupType}
- Specifies the backup type. It must be one of the following: normal, copy, differential, incremental, or daily.
Is it possible to create a scheduled task in windows, that connects to an FTP site, and downloads all the files and folders within the root directory (or specified folders in the root directory) - for example httdocs and subdomains to a local directory?
I figure it must be possible, however i can't quite think of the syntax..
This is to backup my website, to the local drive - i edit and upload content to it (it's wordpress) from various sources.
2 Answers
See my question for the correct script; thanks @djhowell - your script got me started:
Sql Server Execute Batch File
Here's the working script:
lcd
- change LOCAL directorycd
- change REMOTE directorymget *.*
- get all files in directory
Yes, it's possible using scripting mode (ftp -s). Put something like this in a .BAT file:
And then create a MyFTP.txt file in the same path that contains something like this:
Or specify multiple directories like