Parse text for host list
To run a parallel chemistry program, I need to build the host list. The cluster already has SGE(grid engine) installed and it generates a host list file with the following contents:
compute-1-1.local 2 all.q@compute-1-1.local UNDEFINED compute-2-1.local 2 all.q@compute-1-1.local UNDEFINED The important bits are hostname(ex compute-1-1) and number of cpus to use(ex 2). And for this program, it wants them in this form, a shell variable: HOSTLIST=hostname:cpus=X hostname:cpus=X .... I've tried this script, but it doesn't work Code:
#!/bin/bash |
Not sure I got it right, but:
Code:
export HOSTLIST=$( awk '{printf "%s:cpus=%s ",$1, $2}' hostlist ) Cheers, Tink |
Hey that worked like a charm. I guess I gotta just sit down and read up on awk >_< BTW can no one tell me why my script doesn't work?
|
Quote:
It *does* work. Your only problem is that outside your script HOSTLIST is unknown. Cheers, Tink |
No, this would have ended up part of a larger script where HOSTLIST would have been referenced. The thing was while testing this snip of code, I would put in echo statements to watch the variables and NNODES would come up as zero and I don't know why.
|
Quote:
Maybe your file had DOS line endings or something, as opposed to what you copy & pasted here? Code:
~/tmp$ time ./host.sh Code:
~/tmp$ time export HOSTLIST=$( awk '{printf "%s:cpus=%s ",$1, $2}' hostlist ) Cheers, Tink |
All times are GMT -5. The time now is 06:31 PM. |