- Dec 11, 1999
- 16,560
- 4,473
- 75
Ken_g6, do you have a bash script that would start PrimeGrid at the right time for the challenge?
And perhaps, another one to force an upload at the deadline?
I think I can do one that does both!
But I think it's working now, so here it is for the next race:
Code:
#!/bin/bash
# Wait until the next PrimeGrid race, then kick off BOINC on that race.
thisyear=`date +%Y`
function parsedate {
timestr=`date -u --date "$1" +%s`
echo $timestr
}
# Sleep until the given time, minus the offset in seconds.
function sleepuntil {
timestr="$1"
offset="$2"
localnow=`date -u +%s`
# Get the current time from the PrimeGrid main page.
pgnow=`wget -q -Yoff -O- -T 10 http://www.primegrid.com/ | grep "serverstatus italic" | grep "$thisyear-" | sed -e "s/^[^>]*>//;s/<.*$//"`
pgnow=`date -u --date "$pgnow" +%s`
if [ "$pgnow" == "" ] ; then
echo Warning: PrimeGrid server inaccessible - using local date.
pgnow="$localnow"
fi
let "sleeptime = $timestr-$pgnow-$offset"
if [ "$sleeptime" -gt "0" ] ; then
echo Sleeping $sleeptime seconds, until about $offset seconds before the race time.
sleep $sleeptime
return 0
else
echo Time already passed by $sleeptime seconds!
return 1
fi
}
# Parse out the race date, not from the timer.
racedate=`wget -q -Yoff -O- -T 10 http://www.primegrid.com/ | grep ' \((UTC)\|UTC – \)'`
if [ "$racedate" == "" ] ; then
echo "No PrimeGrid race found."
exit
fi
enddate=`echo "$racedate" | sed -e 's/^.*\( UTC – \| to \)//;s/(\?UTC.*$/UTC/' | sed -e "s/ \([0-9]\+:\)/ $thisyear \1/"`
racedate=`echo "$racedate" | sed -e 's/\( to .*\)\?UTC.*$/ UTC/;s/^.*>//' | sed -e "s/ \([0-9]\+:\)/ $thisyear \1/"`
#racedate=`wget -q -Yoff -O- -T 10 http://www.primegrid.com/ | grep "MissionTimer(" | sed -e 's/^[^"]*"//;s/".*$//'`
racedate=`parsedate "$racedate"`
if [ "$enddate" != "" ] ; then
echo Race will end $enddate
enddate=`parsedate "$enddate"`
fi
if sleepuntil "$racedate" 300 ; then
boinccmd --project http://www.primegrid.com/ suspend
# Find all incomplete PrimeGrid tasks and abort them.
for i in `boinccmd --get_tasks | grep "^ \(project URL\|state\|name\): " | grep -A 1 -B 1 "http://www.primegrid.com" | grep -B 2 "^ state: [^5]" | grep "^ name: " | sed -e "s/^ name: //"` ; do
boinccmd --task http://www.primegrid.com/ $i abort
done
fi
toflush=`boinccmd --get_tasks | grep "^ \(project URL\|state\): " | grep -A 1 "http://www.primegrid.com" | grep "^ state: 5" | wc -l`
if [ "$toflush" != "0" ] ; then
boinccmd --project http://www.primegrid.com/ update
fi
if sleepuntil "$racedate" 0 ; then
# Suspend all projects.
for i in `boinccmd --get_project_status | grep "^ master URL: " | sed -e "s/^ master URL: //"` ; do
boinccmd --project $i suspend
done
# Start PrimeGrid.
boinccmd --project http://www.primegrid.com/ resume
boinccmd --project http://www.primegrid.com/ allowmorework
boinccmd --project http://www.primegrid.com/ update
else
echo Race already started!
fi
# For the next up-to-30 days, flush before the race start time.
if [ "$enddate" != "" ] ; then racedate="$enddate"
else let "racedate = $racedate + 86400"
fi
for I in `seq 1 30` ; do
sleepuntil "$racedate" 3600
istimer=`wget -q -Yoff -O- -T 10 http://www.primegrid.com/ | grep "MissionTimer(" | wc -l`
if [ "$istimer" == "0" ] ; then break ; fi
for j in 1800 900 450 225 100 10 1 0 0 ; do
toflush=`boinccmd --get_tasks | grep "^ \(project URL\|state\): " | grep -A 1 "http://www.primegrid.com" | grep "^ state: 5" | wc -l`
if [ "$toflush" != "0" ] ; then
boinccmd --project http://www.primegrid.com/ update
echo Flushing $toflush tasks!
fi
sleepuntil "$racedate" $j
done
if [ "$enddate" != "" ] ; then break; fi
sleep 3600
istimer=`wget -q -Yoff -O- -T 10 http://www.primegrid.com/ | grep "MissionTimer(" | wc -l`
if [ "$istimer" == "0" ] ; then break ; fi
let "racedate = $racedate + 86400"
done
echo "Race over!"
# Resume all projects.
#for I in `boinccmd --get_project_status | grep "^ master URL: " | sed -e "s/^ master URL: //"` ; do
#boinccmd --project $I resume
#done
Uncomment that last section if you want to let BOINC do something else when the race ends.
Edit 6/8/10: Fixed for recent timer changes: they now do a countdown to the end.
Edit 12/15/12: Changed all references to "result" to "task". Change them back for pre-6.12 BOINC clients, or upgrade.
Edit 3/10/13: I think this fixes when allowmorework should be called.
Last edited: