How to execute one batch file occasionally? - batch-file

Hey guys I have troubles writing batch file, could you help me with it? I want to write bat file that executes occasionally(every 2-3 hours for instance). I want to accomplish something like this:
cd D:\Repositories\myRepo
git checkout master
git pull
cd D:\Repositories\myRepo2
git checkout master
git pull
I know that in unix based OS there is command that there is inotifywatch command that can help me execute that file over period but I don't know what can do this in Windows. Could you help me? Also these six lines that I wrote doesn't seem to be working for some reason? Is there any chance that I execute them one after another because I am not sure if they are waiting one another right now..

Related

Why isn't this cd command working in batch file?

First, some context for the question. I've written a small script that automates most of a tedious process surrounding updating an application I wrote. Each time I reinstall the application, it creates a folder with a name that's an alphanumeric jumble that is different with each install. In my script, I'm trying to cd into this folder. Since it changes every time, I can't just hardcode it.
This is the command I use. It works every single time when I put it into the command line, but only works half the time running from my .bat. When it doesn't work, it just says "the system cannot find the path specified." I'm assuming the issue has to do with the wildcard there at the end, but since it works when I put it directly into CMD, I can't figure out what the problem is.
cd "[filepath]\ED2...tion_*"
Why isn't it working and how can I make it work? Thanks.

How to Create a Simple Batch file for Application Uninstall via CMD?

I am inquiring assistance on creating a simple batch file in order to help field techs at my job remove the Microsoft Exchange Management Console via CMD batch. But for some reason i have been unsuccessful at being to accomplish this.
To my understanding its a matter of changing directories and running a uninstaller.
If i do it manually Run CMD as Admin and copy and paste
cd %ProgramFiles%\Microsoft\Exchange Server\v14\bin\setup.com /m:uninstall
This works flawlessly however when trying to compose it into a batch no go.
#echo off
cd D/ c:\
%ProgramFiles%\Microsoft\Exchange Server\v14\bin\setup.com /m:uninstall
And in theory i am assuming this should do it simple and so i thought but i can not get this thing going. I know i am missing something.
Can someone shed some light on the subject i would be most appreciated.
Thank You.
CD is the command to 'Change Directory'. Try this line to perform the uninstall.
"%ProgramFiles%\Microsoft\Exchange Server\v14\bin\setup.com" /m:uninstall
You need the quotes to handle the spaces in that path. And it is good practice. For future posts remember that it is helpful if you indicate what error or result you are getting.

Batch Script to SSH and deploy cron job via VI

First i would just like to point out, i know very little about this subject matter. Okay, now that that is out of the way.
I am trying to setup a batch script to ssh to a list of IP's (about 50) and create a simple cron job to reboot the box it connects to every 24 hours at midnight local time.
I already create the cron job in VI, but i have no idea how to make this batch script work. I have tried to piece meal a batch together but, have had zero luck. Lastly i think i should mention that i am making the batch file on a windows box, and sshing to a Linux shell. If their is anything you guys need let me know and i will try to supply it.
Thanks in advance!
Edit: for clarity
May this be useful?
HERE
Inside the "commands.txt used in the script i linked to:
shutdown -r -t sec 0 Rebooting
exit

Automate cygwin via batch file

Long story short... we have multiple servers which we run perflog monitoring on every night. My job is to convert these logs to .csv format and send them to my e-mail.
This bit it already automated via a .sh script an ex-employee wrote.
What I want automated is to run a batch job after the perfmon logging to look at a specific folder and find the latest .blg file and run the sh script on it (the script is called upload) so that I don't have to log in to each server and do it manually.
e.g.
upload myInitials cd /cygdrive/someLocation/logs/$latestFile$.blg
myInitials and the location can be hard-coded... I just wouldn't know how to find the latest file in the folder and automate it all via a batch file.
Any pointers would be very helpful!
# Jeremy:
Sorry, I probably should have mentioned in my question that the servers are running 2003 and 2008.
I don't think it would be absolutely necessary to register a change notification on the folder - If the log runs from noon till 7 in the morning, the script will run immediately after (you can set a script to run after a perfmon log has finished in log properties) so the log will almost definitely be the latest file in the folder anyway.
Like I said, I already have a .sh file in place to convert to csv and send to my e-mail, I just need to incorporate it into a batch file so that instead of me going to each of the servers and opening up cygwin and typing upload xx /cygdrive/location/logs/xyz.blg, I can have it automated to run straight after the log has finished without me having to RDC into it.
Thanks for the input!
If you have a Shell script and you job is to call the shell script from a windows batch file then this will work.This assumes the cygwin is installed in C:
Contents of start_cyg.bat
#echo off
set PATH=%PATH%:"C:\Cygwin\bin"
rem bash --login -i
bash "/cygdrive/d/cyg.sh"
Contents of cyg.sh
#!/bin/bash
TAIL=`ls -lrt | tail -1`
echo "TAIL:$TAIL"
If you call start_cyg.bat from windows command prompt you can get the output of the cyg.sh in the console
for getting newest file in a directory, ls -1tr | tail -1 should work.
First, I don't know if it would meet your requirements, but the Windows Task Scheduler 2 in Vista+ is very robust and can trigger an event even based on log entries. However, extraction and parsing of that log entry may require some scripting, and might have concurrency issues, even if that log entry did indicate the last used process. Chances are none of this is helpful, but just throwing it out there.
Programatically, it would be simple as you can register a change notification on a folder. When a change occurs, you go find the latest file. Then launch the batch file to launch your shell script, or whatever your desired sequence may be.
I think cygwin may even support change notification events via scripting, though I'm unsure. I believe there are linux extensions for this, but I may be wrong.
If it were me, I'd just write a little C++ app to do whatever I wanted.. but for you maybe any (or more likely none) of the above helps ;o.

Calling Tortoise from command line and build if new code (how to know if tortoise updated anything)?

I am writing a batch file which is supposed to update the source files from tortoise and - if anything new was gotten - build the solution. Should be a very simple task.
My batchfile looks like this (I've removed the non-essentials)
set updatepath=%1
set solution=%2
set output=%3.txt
call TortoiseProc.exe /command:update /path:%updatepath% /closeonend:2
call %devenv% %solution% /Build Debug /Out %output%
Now, I'd like to know if tortoise actually got new code for me and the not build if it didn't. How do I do this?
I am running Windows Vista
(The batch script is called from another batch script about 7 times - one for each project I need updated and - perhaps - build).
Using tortoise is probably not the best way to resolve the problem.
To begin with, it would help knowing which SCM you're using (Mercurial, Subversion, CVS...). Most (all?) SCM tools come with a command-line interface, as opposed to the tortoise shell extension. If you used e.g. mercurial, this is how you would check if the local files need updating:
d:\projects\myproj> hg incoming <main repository path>
You could then parse the output to check if there are pending changes. A similar approach would work with other SCMs.
TortoiseProc is not meant for this kind of automation:
Remember that TortoiseSVN is a GUI client, and this automation guide
shows you how to make the TortoiseSVN dialogs appear to collect user
input. If you want to write a script which requires no input, you
should use the official Subversion command line client instead.
http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html
So, first, get the command line client ( SlikSVN is my favourite). Note that update in TortoiseProc doesn't bring the dialog in the way you are using, but calling it seven times, you are better off using svn command line client.
Second, use svn status -u to see if there are updates in the repo. --show-updates or -u places an asterisk next to items that are out of date. You can probably grep it.
If so, use svn update to update your working copy.

Resources