问题描述
长话短说...我们有我们运行在每天晚上perflog监控多台服务器。我的工作就是将这些日志转换为.csv格式,并将它们发送到我的邮箱。
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.
这一点它已经通过.SH脚本前雇员写的自动化。
This bit it already automated via a .sh script an ex-employee wrote.
我要的是自动运行的perfmon登录后批处理作业来看看一个特定的文件夹,找到最新的.blg文件,并在其上运行的sh脚本(脚本被称为上传),因此我不必须登录到每个服务器和做手工。
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.
例如
上传myInitials CD /cygdrive/someLocation/logs/$latestFile$.blg
upload myInitials cd /cygdrive/someLocation/logs/$latestFile$.blg
myInitials和位置可以是硬codeD ...我只是不知道如何找到该文件夹中的最新文件并通过批处理文件自动完成这一切。
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!
@杰里米:
对不起,我大概应该在我的问题提到,服务器运行2003和2008。
Sorry, I probably should have mentioned in my question that the servers are running 2003 and 2008.
我不认为这是绝对必要的注册文件夹更改通知 - 如果日志从中午早上一直持续到7,脚本会(你可以设置一个脚本后,运行后立即运行Perfmon日志已日志属性完成),因此日志将几乎肯定会在文件夹中最新的文件呢。
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.
就像我说的,我已经有一个适当的sh文件转换为CSV和发送给我的电子邮件,我只是需要将其纳入一个批处理文件,这样,而不是我去到每个服务器和开放Cygwin和打字上传XX /cygdrive/location/logs/xyz.blg,我可以把它自动化直运行日志已无需RDC我把它完成之后。
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.
感谢您的输入!
推荐答案
如果你有一个Shell脚本,你的工作是从Windows批处理文件调用shell脚本,那么这将work.This假设cygwin的安装在C
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:
@echo off
set PATH=%PATH%:"C:\Cygwin\bin"
rem bash --login -i
bash "/cygdrive/d/cyg.sh"
cyg.sh的
目录
#!/bin/bash
TAIL=`ls -lrt | tail -1`
echo "TAIL:$TAIL"
如果您从Windows调用start_cyg.bat命令提示符,你可以得到cyg.sh在控制台输出
If you call start_cyg.bat from windows command prompt you can get the output of the cyg.sh in the console
这篇关于通过批处理文件自动执行的cygwin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!