eResearch Tips

Linux: Smaller tools and building blocks

Dr Edan Scriven, a QCIF eResearch Analyst at UQ, outlines Linux utilities and tools to help you monitor and control your tasks.

Open-source software Linux is full of utilities and tools to help you monitor and control your tasks. Here's some that I use every day.
 
Do you have a batch job running and want to monitor its output in real time? Or a cloud instance running a server and you want to watch its log output? Linux’s tail command doesn't just show the end of a file. Use tail -f <filename> and it will follow a file as it's being written. It can even follow multiple files, handy for watching a PBS job's stdout and stderr files at the same time.
 
Linux allows you to redirect output elsewhere, into other files and other programs too. Use the pipe— | —to chain multiple commands into more complex tasks. For example, do you pass your job array index into your program but it's off by one, or you'd like to scale it by a non-integer factor? Maybe you can modify your program, but sometimes you can't or it's easier to just tweak your input. You can use the bc command to do basic mathematics in your job submission script, and backticks— ` —to use the output of one command as a parameter of another. For example:
 
# myprog takes a number as a parameter
myprog `echo $PBS_ARRAY_INDEX*1.75 | bc`
 
Or you can use the pipe to filter files for interesting information. If you know your program outputs 'failed to converge after N iterations' when something's not right, you can put tail and | together with a command like grep, like this:
 
tail -f myprog.log | grep 'failed'
 
And now the terminal that's running that command won't display a flood of output—just the bit you're watching for.
 
Many Linux commands are able to be used like this, as the building blocks of larger and more complex processing workflows.