Advanced search

Message boards : GPUGRID CAFE : Small Bash script to check tasks from Linux console

Author Message
Vagelis Giannadakis
Send message
Joined: 5 May 13
Posts: 187
Credit: 349,254,454
RAC: 0
Level
Asp
Scientific publications
watwatwatwatwatwatwatwatwatwat
Message 30652 - Posted: 4 Jun 2013 | 9:38:26 UTC
Last modified: 4 Jun 2013 | 9:41:59 UTC

Hi all,

I wanted to have an easy way to check task progress from the command line and "boinccmd --get_simple_gui_info" doesn't seem to cut it: no elapsed time, no estimation, a ton of things you're not interested in. So, I sat down and wrote the following Bash script. Being contempt with it, I also decided I would share it with my fellow Linux crunchers! So, here goes:

#! /bin/bash

# Name: taskinfo
# Purpose: Bash script to report information about running BOINC tasks
# Creator: Vagelis Giannadakis
# Created: 2013-06-04
# I hereby release this script in the Public Domain, you are free to copy,
# change, enhance, cripple and distribute in any way you see fit.
# Have a sip of your favorite ice-cold Pils / Lager to me, if you find this
# script useful!

# BOINC home - substitute with your own
boincHome="$HOME/BOINC"

if [ $# -eq 0 ]; then
tasks=`find "$boincHome" -name boinc_task_state.xml`
else
while [ $# -gt 0 ]; do
tasks="$tasks $boincHome/slots/$1/boinc_task_state.xml"
shift
done
fi

for task in $tasks; do
# Read task info
slot=`expr match "$task" "$boincHome/slots/\([0-9]\+\)/boinc_task_state.xml"`
taskInfo=`cat $task`

# Read task name
taskName=`echo $taskInfo|grep -Eo '<result_name>[^<]+</result_name>'|sed -r 's/<result_name>|<\/result_name>//g'`

# Parse elapsed time and completion fraction
elapsed=`echo $taskInfo|grep -Eo '<checkpoint_elapsed_time>[0-9.]+</checkpoint_elapsed_time>'|grep -Eo '[0-9.]+'`
fraction=`echo $taskInfo|grep -Eo '<fraction_done>[0-9.]+</fraction_done>'|grep -Eo '[0-9.]+'`

totalH=`echo "scale=2; $elapsed / $fraction / 60 / 60"|bc -l`
elapsedH=`echo "scale=2; $elapsed / 60 / 60"|bc -l`
percentDone=`echo "scale=2; $fraction * 100"|bc -l`
remaining=`echo "scale=2; ($elapsed / $fraction - $elapsed) / 60 / 60"|bc -l`

echo "Slot: $slot"
echo "Task: $taskName"
echo "Elapsed: $elapsedH hours"
echo "Percent done: $percentDone"
echo "Estimated: $totalH hours"
echo "Remaining: $remaining hours"
echo "--------------"
done

You have two ways to use it:
    1. Without arguments ($ taskinfo). This way, it goes through all slots and prints information about each.
    2. With slot numbers separated by spaces ($ taskinfo 1 2). This way, it only prints information about the slots you specified.


Examples:

vagelis@vgserver:~$ taskinfo
Slot: 1
Task: qv143_00076_3
Elapsed: .42 hours
Percent done: 12.500000
Estimated: 3.41 hours
Remaining: 2.98 hours
--------------
Slot: 3
Task: E213664_798_A.33.C26H12OS4Se2.49.3.set1d06_7
Elapsed: 3.61 hours
Percent done: 28.700600
Estimated: 12.60 hours
Remaining: 8.98 hours
--------------
Slot: 0
Task: faah40488_ZINC08739801_1_xPR_wC6_11_1ref9_00_0
Elapsed: .93 hours
Percent done: 27.277100
Estimated: 3.43 hours
Remaining: 2.49 hours
--------------
Slot: 2
Task: I87R7-NATHAN_KIDc22_3-3-8-RND4522_0
Elapsed: 6.94 hours
Percent done: 30.834000
Estimated: 22.51 hours
Remaining: 15.57 hours
--------------
vagelis@vgserver:~$

vagelis@vgserver:~$ taskinfo 2 3
Slot: 2
Task: I87R7-NATHAN_KIDc22_3-3-8-RND4522_0
Elapsed: 7.05 hours
Percent done: 31.334000
Estimated: 22.51 hours
Remaining: 15.46 hours
--------------
Slot: 3
Task: E213664_798_A.33.C26H12OS4Se2.49.3.set1d06_7
Elapsed: 3.61 hours
Percent done: 28.700600
Estimated: 12.60 hours
Remaining: 8.98 hours
--------------


To use, create a new text file with an editor and copy-paste the above into it. Remember to change your BOINC home directory in line 13! Then save (I suggest the file name taskinfo) and make executable (command: chmod +x taskinfo). In my environment, I've placed it in ~/bin/taskinfo. This automatically adds it in the PATH, so I don't have to write its complete name to execute it.

The script uses the BOINC file boinc_task_state.xml in the slots to get information about the running tasks. Sometimes, if the task has just started and not recorded its state yet, the file may not be there, so the task won't be reported by the script. Just run the script again in a couple of minutes.

The script assumes a linear relationship between elapsed time and percent done, in order to calculate the estimated total time for a task. This doesn't always work correctly for all tasks, so the reported estimated and remaining times may not always be correct. Feel free to enhance the script if you know how to handle such cases!

I hope you find this useful and enjoy using!

Cheers!
Vagelis
____________

Vagelis Giannadakis
Send message
Joined: 5 May 13
Posts: 187
Credit: 349,254,454
RAC: 0
Level
Asp
Scientific publications
watwatwatwatwatwatwatwatwatwat
Message 31037 - Posted: 26 Jun 2013 | 12:56:18 UTC

I've done some enhancements since I first released this and thought I should bring it up to date. So, here goes:

#! /bin/bash

# Creator: Vagelis Giannadakis
# Created: 2013-06-04
# I hereby release this script in the Public Domain, you are free to copy,
# change, enhance, cripple and distribute in any way you see fit.
# Have a sip of your favorite ice-cold Pils / Lager to me, if you find this
# script useful!

# BOINC home - substitute with your own
boincHome="$HOME/BOINC"

if [ $# -eq 0 ]; then
tasks=`find "$boincHome" -name boinc_task_state.xml|sort`
else
while [ $# -gt 0 ]; do
tasks="$tasks $boincHome/slots/$1/boinc_task_state.xml"
shift
done
fi

for task in $tasks; do
# Read task info
slot=`expr match "$task" "$boincHome/slots/\([0-9]\+\)/boinc_task_state.xml"`
taskInfo=`cat $task`

# Read task name
taskName=`echo $taskInfo|grep -Eo '<result_name>[^<]+</result_name>'|sed -r 's/<result_name>|<\/result_name>//g'`

# Parse elapsed time and completion fraction
elapsed=`echo $taskInfo|grep -Eo '<checkpoint_elapsed_time>[0-9.]+</checkpoint_elapsed_time>'|grep -Eo '[0-9.]+'`
cpu=`echo $taskInfo|grep -Eo '<checkpoint_cpu_time>[0-9.]+</checkpoint_cpu_time>'|grep -Eo '[0-9.]+'`
fraction=`echo $taskInfo|grep -Eo '<fraction_done>[0-9.]+</fraction_done>'|grep -Eo '[0-9.]+'`

totalS=`echo "scale=0; $elapsed / $fraction"|bc -l`
totalH=`expr $totalS / 60 / 60`
totalM=`expr $totalS / 60 - $totalH \* 60`
elapsedS=`echo "scale=0; $elapsed / 60 * 60"|bc -l`
elapsedH=`expr $elapsedS / 60 / 60`
elapsedM=`expr $elapsedS / 60 - $elapsedH \* 60`
cpuS=`echo "scale=0; $cpu / 60 * 60"|bc -l`
cpuH=`expr $cpuS / 60 / 60`
cpuM=`expr $cpuS / 60 - $cpuH \* 60`
percentDone=`echo "scale=2; $fraction * 100"|bc -l`
remainingS=`echo "scale=0; $elapsedS / $fraction - $elapsedS"|bc -l`
remainingH=`expr $remainingS / 60 / 60`
remainingM=`expr $remainingS / 60 - $remainingH \* 60`

echo "Slot: $slot"
echo "Task: $taskName"
[ $elapsedH -lt 10 ] && elapsedH="0$elapsedH"
[ $elapsedM -lt 10 ] && elapsedM="0$elapsedM"
echo "Elapsed: $elapsedH:$elapsedM"
[ $cpuH -lt 10 ] && cpuH="0$cpuH"
[ $cpuM -lt 10 ] && cpuM="0$cpuM"
echo "CPU time: $cpuH:$cpuM"
echo "Percent done: $percentDone"
[ $totalH -lt 10 ] && totalH="0$totalH"
[ $totalM -lt 10 ] && totalM="0$totalM"
echo "Estimated: $totalH:$totalM"
[ $remainingH -lt 10 ] && remainingH="0$remainingH"
[ $remainingM -lt 10 ] && remainingM="0$remainingM"
echo "Remaining: $remainingH:$remainingM"
echo "--------------"
done


Example output:
vagelis@vgserver:~$ taskinfo 4
Slot: 4
Task: I25R7-NATHAN_KIDKIXc22_1-0-41-RND9457_0
Elapsed: 03:39
CPU time: 03:34
Percent done: 20.416700
Estimated: 17:54
Remaining: 14:13
--------------
vagelis@vgserver:~$


PS: The "code" tag in this forum really sucks! It trims whitespace not only from the beginning / ending of a line, but also from within the line!
____________

Stefan
Project administrator
Project developer
Project tester
Project scientist
Send message
Joined: 5 Mar 13
Posts: 348
Credit: 0
RAC: 0
Level

Scientific publications
wat
Message 31038 - Posted: 26 Jun 2013 | 14:06:12 UTC - in response to Message 31037.
Last modified: 26 Jun 2013 | 14:09:41 UTC

PS: The "code" tag in this forum really sucks! It trims whitespace not only from the beginning / ending of a line, but also from within the line!


I'd go even further and say that this forum software sucks in general. Can't see names of last posts in the forum overview, if there are any new unread posts (you have to go into each sub-forum separately). You cannot delete posts, only hide them, etc. etc. I was thinking of suggesting a switch to another forum software but there is really no-one with the time or willingness to do it at this moment :/ Actually now that I check it looks like it is used by BOINC and provides quite some integration for it so I am guessing it's never going to change :P

Good job on the script though!

Vagelis Giannadakis
Send message
Joined: 5 May 13
Posts: 187
Credit: 349,254,454
RAC: 0
Level
Asp
Scientific publications
watwatwatwatwatwatwatwatwatwat
Message 31039 - Posted: 26 Jun 2013 | 15:03:08 UTC - in response to Message 31038.

I'd go even further and say that this forum software sucks in general. Can't see names of last posts in the forum overview, if there are any new unread posts (you have to go into each sub-forum separately). You cannot delete posts, only hide them, etc. etc. I was thinking of suggesting a switch to another forum software but there is really no-one with the time or willingness to do it at this moment :/ Actually now that I check it looks like it is used by BOINC and provides quite some integration for it so I am guessing it's never going to change :P

Yes, unfortunately changing forum software isn't easy.. Just imagine importing all accounts and all posts and all images and, and...

At the very least, it's fast! Which is a very important thing!

Good job on the script though!

Thanks! :)
____________

Profile skgiven
Volunteer moderator
Volunteer tester
Avatar
Send message
Joined: 23 Apr 09
Posts: 3968
Credit: 1,995,359,260
RAC: 0
Level
His
Scientific publications
watwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwatwat
Message 31042 - Posted: 26 Jun 2013 | 18:57:51 UTC - in response to Message 31039.

I use to use a square box to represent a space, □, but most people wouldn't get it.

Alas, the BB Code in use is not the full BB Code, some features were never incorporated.

The template could do with some work, but the GPUGrid site has already been modified towards the research and I'm sure Toni or whoever has better things to do. Its more of a technicians roll than a researchers roll. Most of these issues would be better addressed by the Boinc high command. Some projects have rebuilt their site, and basically abandoned the old one - a bit of a rough job.

If you just go to Message Boards you can see which forum section the latest posts are in, but not the person who posted. Official announcements tend to be made in the News thread by the researchers, if you don't want to pay too much attention to the general banter. You can also 'Subscribe to threads' of interest, and get an email of new posts, as well as have those threads stand out a bit more.
____________
FAQ's

HOW TO:
- Opt out of Beta Tests
- Ask for Help

Post to thread

Message boards : GPUGRID CAFE : Small Bash script to check tasks from Linux console

//