Commit 8dfa1af8 authored by Hynek Baran's avatar Hynek Baran

Prehistoric and unused bin/* scripts

parent f18d0748
#!/bin/bash
function MakeDir()
{
if [ ! -d $1 ] ; then
mkdir $1
fi
}
function ArchivateDir()
{
JobName=$1
ArchDir=$2
DestDir="${ArchDir}/Archiv.${JobName}/"
echo
echo "Archivating ${ArchDir}/${JobName}*" to ${DestDir} ...
MakeDir ${DestDir}
mv ${ArchDir}/${JobName}* ${DestDir}
#for f in ${ArchDir}/${JobName}* ; do
# mv $f ${DestDir}
#done
echo "... ${ArchDir} done."
}
echo "Archivatiion of $1 starting"
for ArchDir in "Abandoned" "Ready" "Done" "States" "Results" "Logs" "Errors"; do
ArchivateDir $1 ${ArchDir}
done
\ No newline at end of file
#!/bin/bash
function CheckIt ()
{
myFileWithoutExt=${1/.log/}
if [[ -f Done/${myFileWithoutExt}.runme && ! -f Results/${myFileWithoutExt}.divbyzero ]] ; then
echo ${myFileWithoutExt}
fi
}
for koko in `grep -il "error" Logs/*.log` ; do CheckIt `basename $koko` ; done
\ No newline at end of file
#!/bin/bash
Destination=/Volumes/SPEK/Jets
echo "Copying to ${Destination}"
echo
function MakeDir()
{
if [ ! -d $1 ] ; then
mkdir $1
fi
}
MakeDir ${Destination}
MakeDir ${Destination}/mc
cp -R mc/* ${Destination}/mc/
MakeDir ${Destination}/bin
cp -R bin/* ${Destination}/bin/
echo Final
MakeDir ${Destination}/Final
cp -R Final/$1* ${Destination}/Final/
echo Results
MakeDir ${Destination}/Results
cp Results/$1* ${Destination}/Results/
echo States
MakeDir ${Destination}/States
cp States/$1* ${Destination}/States/
echo Ready
MakeDir ${Destination}/Ready
cp Ready/$1* ${Destination}/States/
echo .
#!/bin/bash
#
# $1 job base path (no extensions or directories, just the base
# example: DebugOneStep uyy001
# .mw is created in Test/$1/
function MakeDir()
{
if [ ! -d $1 ] ; then
mkdir $1
fi
}
JobBasePath=$1
MapleWorkDir=Test/${JobBasePath}
JobBaseName=`basename ${JobBasePath}`
MakeDir Test
bin/CreateDirs $MapleWorkDir
InitCmds="restart;\nparCD:=\"${MapleWorkDir}\":\nparBaseFileName:=\"${JobBasePath}\":\nparJobPrefix:=\"${JobBaseName/[0-9\{\}]*/}\":\n"
cp {Done,Ready,Errors/$JobBasePath}/$JobBasePath.runme ${MapleWorkDir}
cd ${MapleWorkDir}
pwd
if [ -f ${JobBaseName}.mw ] ; then
mv ${JobBaseName}.mw ${JobBaseName}.mw.backup
fi
echo -e $InitCmds | global/bin/Parser/GenerateWorkSheet \
global/mc/SingleStep.mc \
${JobBaseName/[0-9\{\}]*/} \
$JobBaseName \
${JobBaseName}.mw
open ${JobBaseName}.mw
\ No newline at end of file
#!/usr/bin/perl -w
#
# $1: .runme file
#######################################################################
sub HistoryOfSingle {
local $SourceFile=shift;
local @FileContent=();
$Deep=$Deep+1;
{
# handle parameters
local $sourceFileBase;
$sourceFileBase=`basename "$SourceFile"`;
$sourceFileBase =~ s/\.runme// ;
chop $sourceFileBase;
if ($parameters{"N"}) {
if ($Deep > $parameters{"N"}) {
return;
}
}
if ($parameters{"o"}) {
local $b ;
$b=(! $parameters{"n"}) || (! ($Deep > $parameters{"n"}));
if ($parameters{"o"}=~/l/ && $b) {
`open "Logs/"${sourceFileBase}".log"`;
}
if ($parameters{"o"}=~/L/ && $b) {
`open "Logs.Detailed/"${sourceFileBase}".log" 2> /dev/null`
or `open "Errors/"${sourceFileBase}"/Logs.Detailed/"${sourceFileBase}".log" 2> /dev/null`;
}
}
}
#print "\n*** $SourceFile : ***\n";
open(FILE, $SourceFile) or die("\nCannot open input file $SourceFile\n");
@FileContent=<FILE>;
close(FILE);
foreach (@FileContent) {
if (/read/) {
local @parsedLine=();
local $base;
@parsedLine=/(read\s*\(\s*\"\s*)(.*)(\.[^\.]*)(\")/g;
$base=`basename $parsedLine[1]`;
chop($base);
HistoryOfSingle ("Done/".$base.".runme");
}
elsif (/Done/) {
}
else {
local $line;
$line=$_;
if ($parameters{"d"}) {
if ($parameters{"d"}=~/n/) {
print "\n";
}
if ($parameters{"d"}=~/f/) {
print "# $SourceFile :\n";
}
}
print $line;
}
}
}
#######################################################################
local @files=();
local %parameters=();
# read arguments
foreach (@ARGV) {
if (/^-/) {
local @parsedArg=();
@parsedArg=/^(\-)([^\=]*)(\=?)([^\=]*)/;
#print "$parsedArg[0],$parsedArg[1],$parsedArg[2],$parsedArg[3]\n";
if ($parsedArg[3]) {
$parameters{$parsedArg[1]}=$parsedArg[3];
}
else{
$parameters{$parsedArg[1]}=".";
}
}
else {
push(@files, $_);
}
}
if (@ARGV == 0 || $parameters{"h"} || $parameters{"H"} || $parameters{"-help"}) {
print "Possible parameters:\n";
print "\t-o=lL opening log files: l opens logs, -L opens detailed logs\n";
print "\t-n=number-of-levels skips opening files, -N=num skips everything \n";
print "\t-d=fn display result control: n separates lines by empty line, f displays also source file names\n";
}
else {
# do the work for all file args
foreach (@files) {
if (@files > 1) { print "\n* $_ :\n";}
$Deep=0;
HistoryOfSingle($_)
}
}
#!/bin/bash
# open */$1.*
echo -n Open */$1.* ?
read koko
if [[ ! $koko = "n" ]] ; then
open */$1.*
fi
\ No newline at end of file
#!/bin/bash
# runs given job
#
# $1 optional job base path
GlobalLog="Logs.Global/`bin/hostname`.$$.log"
### Stopping and quitting
StopDir="InProgress"
StopFiles=("${StopDir}/stop" "${StopDir}/`bin/hostname`.stop" "${StopDir}/$$.`bin/hostname`.stop" "${StopDir}/`bin/hostname`/stop")
QuitFiles=("${StopDir}/quit" "${StopDir}/`bin/hostname`.quit" "${StopDir}/$$.`bin/hostname`.quit" "${StopDir}/`bin/hostname`/quit")
TestFileExist() {
# test whether exist any of files given as arguments and print it
local item
for item in "$@"
do
#echo "Testing \"${item}\""
if [[ -f "${item}" ]] ; then
echo "File ${item} found."
return 1
fi
done
#echo "None found"
return 0
}
TestFileExistSilent() {
# test whether exist any of files given as arguments
local item
for item in "$@"
do
#echo "Testing \"${item}\""
if [[ -f "${item}" ]] ; then
#echo "File ${item} found."
return 1
fi
done
#echo "None found"
return 0
}
TestKeyboard() {
read -n 1 keypress
echo $keypress
}
StopOrQuit() {
# stop or quit if stop/quit file exists
local r
# TODO: read keyboard for ^Q ?
# quit?
TestFileExist ${QuitFiles[*]}
if [[ $? -gt 0 ]] ; then
echo "Quit"
exit 0
fi
# stop?
TestFileExist ${StopFiles[*]}
r=$?
if [[ $r -gt 0 ]] ; then
echo "Stopped..."
while [[ $r -gt 0 ]] # wait unitl all stop files dismiss
do
sleep 1
TestFileExistSilent ${StopFiles[*]}
r=$?
done
echo "Continue"
fi
# quit???
TestFileExist ${QuitFiles[*]}
if [[ $? -gt 0 ]] ; then
echo "Quit"
exit 0
fi
}
###################################################################################################
{ # Test whether the environment is correct
# Check maple
output=`echo 'lprint(diff(x^2,x)); quit();' | maple -q`
if [[ 0 -lt $? ]] ; then
echo "FATAL ERROR: Cannot run Maple. ${output}"
exit $?
fi
if [[ ! $output == '2*x' ]] ; then
echo "WARNING: Maple is corrupted? diff(x^2,x) is not 2*x but $output."
#echo "FATAL ERROR: Maple is corrupted, diff(x^2,x) is not 2*x but $output."
#exit 254
fi
# check the existence of crucial global directories and files
if [ ! -d "mc/" ] ; then
echo "FATAL ERROR: missing mc directory, cannot run maple."
exit 255
fi
for x in "mc/SingleStep.mc" "mc/CommonProc.mc" "mc/Jets.s"; do
if [ ! -f "$x" ]; then
echo "FATAL ERROR: Missing file ${x}."
exit 255
fi
done
for x in "Results" "States" "Ready" "Errors" "Logs" "InProgress" "Done" "Abandoned"; do
if [ ! -d "$x" ]; then
echo "FATAL ERROR: Direcory ${x} doest not exists."
exit 255
elif [ ! -w "$x" ]; then
echo "FATAL ERROR: Direcory ${x} is not writable."
exit 255
fi
done
# create the base dir InProgress/<hostname> if neccessary
BaseDir=`bin/hostname`
if [ -f "InProgress/${BaseDir}" ] ; then
echo "FATAL ERROR: The exists a file InProgress/${BaseDir}"
echo " in the place where directory of the same name is to be created:"
echo "`ls -la InProgress`"
exit 255
fi
if [ ! -d "InProgress/${BaseDir}" ] ; then
mkdir "InProgress/${BaseDir}"
fi
# check the base dir
if [ ! -d "InProgress/${BaseDir}" ] ; then
echo "FATAL ERROR: Cannot create base directory InProgress/${BaseDir}"
exit 255
elif [ ! -w "InProgress/${BaseDir}" ] ; then
echo "FATAL ERROR: Base directory InProgress/${BaseDir} is not writeable."
exit 255
fi
}
if [[ ! -f ${GlobalLog} ]] ; then
echo "Global log created at `date \"+%H:%M:%S %d/%m/%y\"`" > ${GlobalLog}
fi
###
echo "Run $* started at `date \"+%H:%M:%S %d/%m/%y\"` on host `bin/hostname`, pid is $$"
echo "Run $* started at `date \"+%H:%M:%S %d/%m/%y\"` on host `bin/hostname`, pid is $$" >> ${GlobalLog}
# open ${GlobalLog} 2>/dev/null
while [[ 1=1 ]]
do
StopOrQuit
{
if [[ -f ${QuitFile} ]] ; then
echo "File ${QuitFile} found, quitting."
exit
fi
# take one file prefering *0.runme
#myFile=`ls -1t Ready/$1*s*0*.runme | tail -1 ` # premature success take first
#if [[ $myFile = "" ]] ; then
# myFile=`ls -1t Ready/$1*s*.runme | tail -1 `
#fi
#
#if [[ $myFile = "" ]] ; then
# myFile=`ls -1t Ready/$1*0.runme | tail -1 `
#fi
#if [[ $myFile = "" ]] ; then
# myFile=`ls -1t Ready/$1*0*.runme | tail -1 `
#fi
fileList=`ls -1t Ready/$1*.runme`
myFile=`echo "${fileList}" | egrep "${1}[02468]*\.runme" | tail -1` # take zero only first
if [[ $myFile = "" ]] ; then
myFile=`echo "${fileList}" | egrep "${1}[0-9]*[02468]\.runme" | tail -1` # last zero first
fi
if [[ $myFile = "" ]] ; then
myFile=`echo "${fileList}" | tail -1` # take any
fi
if [[ $myFile = "" ]] ; then # no runme file
echo -n "."
sleep 10
else
{
lastLine=`tail -1 $myFile`
if [[ -w $myFile && $lastLine = '# Done' ]] ; then
{
myBase=`basename $myFile`
myFileWithoutExt=${myBase/.runme/}
echo -n "$myFileWithoutExt (`date \"+%H:%M:%S %d/%m/%y\"`) "
bin/RunOneStep $myFileWithoutExt "-q" 1>> ${GlobalLog} 2>&1
result=$?
{
black='\E[30;50m'
red='\E[31;50m'
green='\E[32;50m'
yellow='\E[33;50m'
blue='\E[34;50m'
magenta='\E[35;50m'
cyan='\E[36;50m'
white='\E[37;50m'
echo -e $red
grep -i "error" Logs/${myFileWithoutExt}.log
if [[ $result -lt 10 ]] ; then
echo -ne $black
if [[ $result -eq 0 ]] ; then
echo "done (`date \"+%H:%M:%S %d/%m/%y\"`)."
elif [[ $result -eq 1 ]] ; then
echo -ne $green
echo "ignored, queued back (`date \"+%H:%M:%S %d/%m/%y\"`)."
else
echo "done with maple result $result (`date \"+%H:%M:%S %d/%m/%y\"`)."
fi
else
if [[ $result -lt 255 ]] ; then
echo -ne $cyan
echo "done with maple result $result (`date \"+%H:%M:%S %d/%m/%y\"`)."
else
echo -ne $red
echo "Fatal error in DoOneStep, exit (`date \"+%H:%M:%S %d/%m/%y\"`)."
exit 255
fi
fi
tput sgr0
}
sleep 1
}
else
sleep 5
fi
}
fi
}
done
\ No newline at end of file
#!/bin/bash
# runs given job
#
# $1 optional job base path
GlobalLog="Logs.Global/`bin/hostname`.$$.log"
StopFile="InProgress/stop"
QuitFile="InProgress/quit"
{ # Test whether the environment is correct
# Check maple
output=`echo 'lprint(diff(x^2,x)); quit();' | maple -q`
if [[ 0 -lt $? ]] ; then
echo "FATAL ERROR: Cannot run Maple. ${output}"
exit $?
fi
if [[ ! $output == '2*x' ]] ; then
echo "FATAL ERROR: Maple is corrupted, diff(x^2,x) is not 2*x but $output."
exit 254
fi
# check the existence of crucial global directories and files
if [ ! -d "mc/" ] ; then
echo "FATAL ERROR: missing mc directory, cannot run maple."
exit 255
fi
for x in "mc/SingleStep.mc" "mc/CommonProc.mc" "mc/Jets.s"; do
if [ ! -f "$x" ]; then
echo "FATAL ERROR: Missing file ${x}."
exit 255
fi
done
for x in "Results" "States" "Ready" "Errors" "Logs" "InProgress" "Done" "Abandoned"; do
if [ ! -d "$x" ]; then
echo "FATAL ERROR: Direcory ${x} doest not exists."
exit 255
elif [ ! -w "$x" ]; then
echo "FATAL ERROR: Direcory ${x} is not writable."
exit 255
fi
done
# create the base dir InProgress/<hostname> if neccessary
BaseDir=`bin/hostname`
if [ -f "InProgress/${BaseDir}" ] ; then
echo "FATAL ERROR: The exists a file InProgress/${BaseDir}"
echo " in the place where directory of the same name is to be created:"
echo "`ls -la InProgress`"
exit 255
fi
if [ ! -d "InProgress/${BaseDir}" ] ; then
mkdir "InProgress/${BaseDir}"
fi
# check the base dir
if [ ! -d "InProgress/${BaseDir}" ] ; then
echo "FATAL ERROR: Cannot create base directory InProgress/${BaseDir}"
exit 255
elif [ ! -w "InProgress/${BaseDir}" ] ; then
echo "FATAL ERROR: Base directory InProgress/${BaseDir} is not writeable."
exit 255
fi
}
if [[ ! -f ${GlobalLog} ]] ; then
echo "Global log created at `date \"+%H:%M:%S %d/%m/%y\"`" > ${GlobalLog}
fi
###
echo "Run $* started at `date \"+%H:%M:%S %d/%m/%y\"`" >> ${GlobalLog}
open ${GlobalLog} 2>/dev/null
while [[ 1=1 ]]
do
if [[ -f ${StopFile} ]] ; then
echo "stopped by ${StopFile}"
while [[ -f ${StopFile} ]]
do
sleep 1
done
echo unstopped, lets go...
else
{
if [[ -f ${QuitFile} ]] ; then
echo "File ${QuitFile} found, quitting."
exit
fi
# take one file prefering *0.runme
#myFile=`ls -1t Ready/$1*s*0*.runme | tail -1 ` # premature success take first
#if [[ $myFile = "" ]] ; then
# myFile=`ls -1t Ready/$1*s*.runme | tail -1 `
#fi
#
#if [[ $myFile = "" ]] ; then
# myFile=`ls -1t Ready/$1*0.runme | tail -1 `
#fi
#if [[ $myFile = "" ]] ; then
# myFile=`ls -1t Ready/$1*0*.runme | tail -1 `
#fi
fileList=`ls -1t Ready/$1*.runme`
myFile=`echo "${fileList}" | egrep "${1}[13579]*\.runme" | tail -1` # take nonzero only first
if [[ $myFile = "" ]] ; then
myFile=`echo "${fileList}" | egrep "${1}[0-9]*[13579]\.runme" | tail -1` # last nonzero first
fi
if [[ $myFile = "" ]] ; then
myFile=`echo "${fileList}" | tail -1` # take any
fi
if [[ $myFile = "" ]] ; then # no runme file
echo -n "."
sleep 10
else
{
lastLine=`tail -1 $myFile`
if [[ -w $myFile && $lastLine = '# Done' ]] ; then
{
myBase=`basename $myFile`
myFileWithoutExt=${myBase/.runme/}
echo -n "$myFileWithoutExt (`date \"+%H:%M:%S %d/%m/%y\"`) "
bin/RunOneStep $myFileWithoutExt "-q" 1>> ${GlobalLog} 2>&1
result=$?
{
black='\E[30;50m'
red='\E[31;50m'
green='\E[32;50m'
yellow='\E[33;50m'
blue='\E[34;50m'
magenta='\E[35;50m'
cyan='\E[36;50m'
white='\E[37;50m'
echo -e $red
grep -i "error" Logs/${myFileWithoutExt}.log
if [[ $result -lt 10 ]] ; then
echo -ne $black
if [[ $result -eq 0 ]] ; then
echo "done (`date \"+%H:%M:%S %d/%m/%y\"`)."
elif [[ $result -eq 1 ]] ; then
echo -ne $green
echo "ignored, queued back (`date \"+%H:%M:%S %d/%m/%y\"`)."
else
echo "done with maple result $result (`date \"+%H:%M:%S %d/%m/%y\"`)."
fi
else
if [[ $result -lt 255 ]] ; then
echo -ne $cyan
echo "done with maple result $result (`date \"+%H:%M:%S %d/%m/%y\"`)."
else
echo -ne $red
echo "Fatal error in DoOneStep, exit (`date \"+%H:%M:%S %d/%m/%y\"`)."
exit 255
fi
fi
tput sgr0
}