Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 644
emtunc Avatar asked Dec 21 '22 22:12

emtunc


1 Answers

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

like image 184
Raghuram Avatar answered Jan 15 '23 08:01

Raghuram