Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, October 22, 2009

Running Scripts

In science it seems that we are supposed to somehow organically learn how to use linux computers. I don't know how people do this. I feel like I know only 15 commands because I use them everyday. Everything else I need to do on linux I either have to ask others to help me, or I look it up when I need it and then promptly forget. All books on the subject seem to give me more information than I need. Is there a 'Practical Linux for Dummies' book?

However, one of the MANY benefits of dating a computer scientist (for those who haven't tried it, I highly recommend it) is that Adam knows how to do almost anything I would want to do on a computer. I've lost track of how many times he has helped me.

Latest example of this is running a script remotely the need to stay logged into the computer. I know this is a basic task, but every time I've tried to get someone to show me how to do it, I've never gotten a clear-cut answer.

So this is how I did it (I am writing it here so that I when I promptly forget how to do this, it will be easy to remind myself):

1) At the top of your python code put the following line (after the import statements):
if __name__ == '__main__':
For more info.

2) Indent the rest of your code (as python requires you to do for all functions)

3) Make sure your code doesn't plotting in it.

4) Save your code as a python script (i.e. code2run.py)

5) In a terminal window type the following:
> python code2run.py code2run.out 2> code2run.err &

6) Check that your code is running by typing the command: top

7) Now you can close your terminal window and come back to check on the run later by typing "top" again.

8) Any outputs to the terminal will go to the file code2run.out, and error messages will go to code2run.err

It would be nice if I could include in this script something where it would email me or send me some sort of message once the run is complete. Anyone know how to do this?