Create log file when running a windows script file - windows

I am running a windows script file, via a task scheduler, which carries out some basic tasks. I need to record each command in a temporary log file.
I have seen some examples on the web, but most seem to suggest having each command line tagged with the >> marker. This is tedious for my scripts, have over 100 commands.
Is there a way to do what I want to do, with some global commands in the script file
Many thanks
ash

Related

Is there a command in Shell scripting for executing .exe file and running commands automatically inside of it? replacing the user interaction

I have a .sh script file that I'm modifying which runs an .EXE file that opens the Windows command line prompt automatically.
This .exe asks the user for an input (name of the file in the folder workspace that it will read)
I want to automate this step in my shell script so my user doesn't have to interact with this, and run the commands automatically
I read a bit about the expect command but I think that is for Linux only.
Can someone help me, I'm pretty new to Shell scripting and I couldn't find any useful information elsewhere.
I'm assuming that your executable accepts command-line arguments. So, here we go.
You can use the "start" command in Windows Shell. For example:
start C:\path\to\program.exe -argument
If you want to make the script wait until the .exe file finishes running before continuing, you can use the "/wait" command:
start /wait C:\path\to\program.exe -argument
IF all of that doesn't work, please try:
start myprogram.exe /command1 /command2 /command3
Hope it helps,

How do I schedule an scp job on Windows?

First of all, I am not an expert programmer, and I don't know much of the programmer's lingo. So please bear with me.
I am using Cygwin on windows, to copy a file from home directory to a remote server (which uses Linux) using SCP. I need to do this every day and so I want to automate it. I know how to schedule tasks in task scheduler, but I don't know what kind of file to save an scp command as. Please help? Oh and I don't have admin access, so I cannot install or use third party applications
First add Cygwin to your Windows Environment Variables. You can find directions on how to do that here (the directions you need are almost all the way at the bottom of the page). Now you should be able to run Linux commands from the command prompt. Simply make a .bat file in notepad with the commands you need to run. It should look something like this:
scp /cygdrive/d/test.txt <linux ip>:/etc/var/test/test.txt
Then use task scheduler to run the .bat file.

How to create and execute a file full of commands on Windows command prompt?

Example:
In Linux we can put the desired commands in a file and give it executable permissions. This helps us to actually run the file on the terminal and thus all the commands inside the file get automatically executed.
How to achieve this on Windows XP?
Same thing, but it's called a batch file, extension is .bat. You can also double-click to run these. This site is a great resource.

How to create an executable command prompt script

I usually perform actions in the 7zip command line program. I was thinking about creating a small script to do everything automatically, but I have never written any Windows shell script before and therefore don't even know where to begin.
I would like to make an executable script file which, when a user double-clicks on it, will call the 7zip command line and perform some actions.
First of all, is this possible? And if it is, what is the best way to do this?
You can create a batch script to do this.
It's basically command line commands that run one after another so you don't have to keep typing them in :)
Put the commands you would normally use for 7zip in a notepad file and save it with the extension .bat, then run it.
7z blah blah params
7z more params and args
All your commands will be executed automatically when the previous one finishes.
There are other programming languages you could do this in (or even VBScript) but batch would be perfectly suited to this, and you don't need to install anything extra.
Batch files can run a series of command line commands. Simply create a text file and name it with the .bat extension.
There are plenty of resources on the internet which will provide you with help.

Scheduled Task: Directory cleanup using windows batch script

I have a shared disk that I would like to clean up once per week using a scheduled task of some sort. I would like to use a batch script so that the system admins can easily modify it or reuse it on other directories when needed.
The directory has files with multiple file extensions but the ones that need to be deleted end in .bkf and must be over 2 weeks old.
Does anyone have a batch script solution for this windows server (not sure which version)?
If you have PowerShell (or can install it), check out this link: http://thepowershellguy.com/blogs/posh/archive/2007/12/13/hey-powershell-guy-how-can-i-delete-files-that-are-a-specified-number-of-hours-old.aspx
Take a look at this page - scheduling tasks from command line
It shows you hot to create scheduled tasks from the command line. You might be able to use this in combination with other dos commands to get your result.
The only thing that needs to be in the batch file is
#echo off
cls
del C:\some\directory\*.bkf
And the delete path can also be sent to this batch script as an argument so that the directory is changeable.
I ended up just writing an EXE that accepts parameters and scheduling that. Unfortunately the other solutions didn't have the flexibility needed.
have you looked into forfiles.exe?
http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/

Resources