#!/usr/bin/perl
use CGI qw(param);

$home = "/usr/local/e-cron";
$jobnet = param("jobnet");
$project = param("project");
$jobname = param("jobname");
$batch_name = param("batch_name");
$code = param("code");
$tmp_file = "/tmp/${project}${jobnet}${batch_name}.tmp";

$code =~s/\r\n/\n/g ;

# update batch
open(BATCH,">$tmp_file");
print BATCH "$code" ;
close(BATCH);

system("sudo -u ejobmgr cp $tmp_file $home/project/$project/$jobnet/bat/$batch_name");
system("sudo -u ejobmgr chmod 755 $home/project/$project/$jobnet/bat/$batch_name");

print "Content-type: text/html\n\n";
###############contents insert#########
system("cat ../elements/header");
print "<h4>Batch has successfully updated. please distribute it</h4>";
print "&nbsp;&nbsp;&nbsp;<a href=\"./set_jobnet_form.cgi?${project},${jobnet}\">Back to Jobnet and Distriute to Servers !</a>";
print "<br></br>";

system("rm $tmp_file");
