Script Center >
Scripting Forums
>
The Official Scripting Guys Forum!
>
VB Script to shcedule a task in remote server
VB Script to shcedule a task in remote server
- In our Project We are using a perl script which copies files from FTP site to our local server.
and we provide the parameters to that Script as <ftp address> <user_name> <Passwd> <FTP_Dir> <Local server Path where the files has to get copy>
and that above thing we use to shcedule as a task to run every 10 min and should run with previllage of user name and passwd and the task should repeat every 23:59 min..
For this every day we need to login to that server every day and have to create a schedule task.
So my idea is to like if we could have had some vb script or some GUI foram so that it will some what make easy the work.
So plz if any body help me in this and plz give me some vb script..
Basically the Server is physically located in USA, But we need to RDP to that server every day and have to create a Shcedule task in that.. Its quite hectick every day..
Please some body help me..
and the Perl Scrpt which we use to copy files is as bellow.
#!/usr/bin/perl use Net::FTP; use Getopt::Std; my $LOCK_FILE = "hiperf.lock"; my $move = 0; my %options = (); getopts("m", \%options); if ($options{m}) { $move = 1; } if ($#ARGV != 4) { die("Usage: download_files.pl hostname user password remote-directory local-directory"); } my $hostname = $ARGV[0]; my $username = $ARGV[1]; my $password = $ARGV[2]; my $remoteDir = $ARGV[3]; my $localDir = $ARGV[4]; my %downloadedMap = (); my $downloadedList = "$localDir/downloadedlist.txt"; # Read dowloaded list open(FILE, "$downloadedList"); while (<FILE>) { chop; #print "Adding $_ to the map\n"; $downloadedMap{$_} = 1; } close(FILE); my $ftp = Net::FTP->new($hostname) or die "Cannot connect to $hostname"; $ftp ->login($username, $password) or die "Cannot login using user: $username: ", $ftp->message; if ($remoteDir ne ".") { $ftp->cwd($remoteDir) || die "Unable to change directory to $remoteDir"; } $ftp->binary; print "Getting file list ...\n"; my @remoteList = $ftp->ls(); print "Done $#remoteList\n"; # Check if lock file exists if (grep(/"$LOCK_FILE"/, @remoteList)) { die "$LOCK_FILE exists on remote ftp server. Quitting."; } open(FILE, ">>$downloadedList"); if (!(-e "$localDir/$LOCK_FILE")) { open(LOCK, ">$localDir/$LOCK_FILE"); close(LOCK); } foreach $file (@remoteList) { next if ($downloadedMap{$file}); if ((!($file =~ /^enc_/)) && (!($file =~ /^dkcbusy_/)) && (!($file =~ /^pairstat_/)) && (!($file =~ /^ldevio_/)) && (!($file =~ /^portio_/)) && (!($file =~ /^clprbusy_/)) && (!($file =~ /^perf_/)) && (!($file =~ /^conf_/))) { #print "$file\n"; next; } # Extract YYYYMMDD HHMMSS my ($ymd, $hms) = $file =~ /[A-Za-z]+_(\d+)_(\d+)/; #print "ymd = $ymd, hms = $hms\n"; next if (($ymd eq "") || ($hms eq "")); if ($ftp->get($file, "$localDir/$file")) { if ($move) { # Move the file to yyyymmdd folder $ftp->mkdir($ymd); if (!$ftp->rename($file, "$ymd/$file")) { print "Unable to move $file to $ymd/$file\n"; next; } } print "Dowloaded file $file\n"; print FILE "$file\n"; } else { print "Unable to download $file: " , $ftp->message, "\n"; } } close(FILE); unlink("$localDir/$LOCK_FILE");and the Ex of Scheduled task is as bellow..
C:\Perl\bin\perl.exe "C:\HiPERF Installers\download_files.pl" -m 207.126.248.84 allstate "allstate" 23388\ "E:\tmeacsv2\Allstate\23388\data"
Please help me...
Madhu Adavi
Answers
- Hello there, the automation for this am looking is for to avoid everytime logging into the remote server.. so if i need to create .cmd file meanse should i need to create cmd file on remote server only or if i create the cmd file in my local system and if i shcedule it from my local system that meanse my system has to be online everytime to then only the shcedule task will run i belive.. am i right..?
if then plz provide me some vb script which has to create the .cmd file on that remote machine only without loggin into that and later i can shcedule the cmd file as u said earlier
Thanks and regds
Madhu
Madhu Adavi- Marked As Answer bymadhuadavi Monday, November 09, 2009 12:56 PM
All Replies
- Try Schtasks.exe from Microsoft available on Windows 2003, to schedule the task on any computer from location.
- I found this article:
http://blogs.technet.com/heyscriptingguy/archive/2009/03/30/how-can-i-create-a-scheduled-task-on-a-number-of-computers.aspx
Also, maybe you could modify the perl script to read parameters from a text file that you store somewhere? This might save you from modifying the scheduled task - just modify a text file instead. - Hello sir,
As u sujjested am using the above command.
But the thing is that am shceduling the perl file where we have to provide some arguiments for that perl file also.. and bellow is the command am using, bt still getting error.
schtasks /create /S usinddm02.corp.hds.com /SC MINUTE /MO 10 /TN TEST /TR C:\download_files.pl -m 207.126.248.84 acs acs321 45610 E:\tmeacsv2\ACS\45610\data /ST 18:30 /RU ****** /RP ******
Help me plz..
Madhu Adavi - Hello,
Create a .cmd file (shell script) that contains the perl command line you want to use; e.g.
perl C:\download_files.pl -m 207.126.248.84 acs acs321 45610 E:\tmeacsv2\ACS\45610\data
and schedule the execution of the .cmd file.
Bill - Hello there, the automation for this am looking is for to avoid everytime logging into the remote server.. so if i need to create .cmd file meanse should i need to create cmd file on remote server only or if i create the cmd file in my local system and if i shcedule it from my local system that meanse my system has to be online everytime to then only the shcedule task will run i belive.. am i right..?
if then plz provide me some vb script which has to create the .cmd file on that remote machine only without loggin into that and later i can shcedule the cmd file as u said earlier
Thanks and regds
Madhu
Madhu Adavi- Marked As Answer bymadhuadavi Monday, November 09, 2009 12:56 PM

