#$oldfile = '/tmp/ipptopsps.old.status.txt';
#$newfile = '/tmp/ipptopsps.new.status.txt';

#`mv $newfile $oldfile`;
#`ssh ippc19 'mysql -h ipp006 -u dvo -pdvo ipptopsps2 < ~/cronjobscripts/checkipptopspsloading.sql > $newfile`;

$running = `ssh ippc19 'ssh ippx001 ps auxw | grep run.ipptopsps|  grep 2017 |grep -v auxw| wc -l '`;

$ans = `ssh ippc19 'ssh ippx001 ps auxw | grep loader | grep py | grep -v auxw |  wc -l '`;

chomp $running;
chomp $ans;

if ($running > 0 ) {
    print "still restarting loaders, there are $running thread(s) starting up loaders\n";
}
if ($ans < 64) {
    print "loaders not fully running, there are $ans / 64 running loaders\n";
}

$numloadersleft = `ssh ippc19 'mysql -h ipp106 -u dvo -pdvo ipptopsps2 -e "select name, count(*) from pending join box on box_id = id join skychunk on name = skychunk group by name" | wc'` -1;

print "there are $numloadersleft loaders left\n";

#@stuff = `ssh ippc19 'mysql -h ipp106 -u dvo -pdvo ipptopsps2 -e "select  batch_type , count(*), date(timestamp) as date, hour(timestamp) as hour  from batch where loaded_to_datastore = 1 and dvo_db = \'LAP.PV3.MERGE\' and (batch_type = \"FW\" or batch_type = \"ST\") and date(timestamp) > '2017-08-19' group by batch_type, date"'`;

#@stuff = `ssh ippc19 'mysql -h ipp106 -u dvo -pdvo ipptopsps2 -e "select  batch_type , count(*), date(timestamp) as date, hour(timestamp) as hour  from batch where loaded_to_datastore = 1 and dvo_db = 'LAP.PV3.MERGE' "'`;

$com = "mysql -h ipp106 -u dvo -pdvo ipptopsps2 -e \"select  datastore_product , count(*), date(timestamp) as date, hour(timestamp) as hour from batch where loaded_to_datastore = 1 and dvo_db = \'LAP.PV3.MERGE\' and date(timestamp) > \'2018-1-13\' group by batch_type, date, hour limit 10\"";

print $com;

@stuff = `ssh ippc19 '$com'`;
#@stuff = `ssh ippc19 'mysql -h ipp106 -u dvo -pdvo ipptopsps2 -e "select  datastore_product , count(*), date(timestamp) as date, hour(timestamp) as hour from batch where loaded_to_datastore = 1 and dvo_db = \'LAP.PV3.MERGE\' and date(timestamp) > \'2018-1-13\' group by batch_type, date, hour limit 10"'`;


foreach $thing (@stuff) {
    print $thing;
}


#select count(*), name from pending join box on box_id = id join skychunk on name = skychunk group by batch_type;

#select datastore_product , count(*), date(timestamp) as date  from batch where loaded_to_datastore = 1 and dvo_db = "LAP.PV3.MERGE" and (batch_type = "ST") group by batch_type, date;









#make hash of new


#subtract off old


#check loader file to see what's currently not running
#while (<>) {


#}
