Automation Script

Advertisement

bainwave
Joined:
Posts:
3
Location:
India

Automation Script

Hi Experts,
Am new to scripting, need your help in building an script, which can run in Task Scheduler.
Here goes my scenario...
I have Linux box (cent OS), in which every day *.txt files will be created in the following format
"20130813-091152-1376365312.882813.txt". Every day roughly 600 files will be created.
I have an other box with Windows OS(Server 2008) with huge space in d drive.
My requirement is as follows...
1. Should Create a sub-folder and name it in date format (yyyymmdd)on windows box.
2. copy all the related data, basing on the date stamp from Linux to the newly created folder
3. Delete all the data basing on the date stamp, from the Linux box.
4. Like wise everyday a new folder shall be created and all the data should be moved from Linux to windows box.
5. Finally, the trick is, this script should work only on condition, where Today minus 15 Days is the condition. Means it should start working only on the files, which were 15 days back from today, leaving all these 15 days on the Linux box.

I tried different combinations of the scripting, available in this forum, but in vain.

I need your help in building a script
Hope am clear in asking.

Thanks in advance.

Reply with quote

Advertisement

bainwave
Joined:
Posts:
3
Location:
India

Here it goes

// Function to figure out the date of the previous business day
// in the format YYYYMMDD including place holding zeros.
function PreviousBizDay() {
function D2( val ) {
return ( ( val < 10 ) ? '0' : '' ) + val;
}
var today = new Date();
today.setDate( today.getDate() - 1 ); // Yesterday...
while ( ( today.getDay() < 1 ) || ( today.getDay() > 5 ) ) {
today.setDate( today.getDate() - 1 ); // Previous day
}
return today.getFullYear() + D2( today.getMonth() + 1 ) + D2( today.getDate() )
}
// Local path to download to (MUST keep trailing slashes)
var LOCALPATH = "d:\\logs\\";
// Remote path to search in (MUST keep trailing slash)
var REMOTEPATH = "/var/spool/monitor";
// Session to connect to
var SESSION = "root:xxxxxxx@10.10.10.10";
// Path to winscp.com (MUST keep trailing slashes)
var WINSCP = "c:\\program files\\winscp\\winscp.com";
var filesys = WScript.CreateObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");
var FILE1 = "file." + PreviousBizDay() + ".".txt";
var exec;

// Run WINSCP and download the 3 files, then exit
exec = shell.Exec("\"" + WINSCP + "\"");
exec.StdIn.Write(
"option batch abort\n" +
"option confirm off\n" +
"open \"" + SESSION + "\"\n" +
"get \"" + REMOTEPATH + FILE1 + "\" \"" + LOCALPATH + "\"\n" +
"exit\n");

Reply with quote

Advertisement

You can post new topics in this forum