I have a bunch of scripts that I run periodically from the command line by SSHing into a server and running the command. The problem is that sometimes these scripts can take a while and I might lose connectivity, want to reboot my machine, whatever. Yes, you can run these in the background or use nohup, but I want to run these interactively in the foreground and watch the output. Enter screen.
Screen is a windows manager for your command line sessions and is extremely powerful. I am not going to get into all that it can do but am going to simply focus on how easy it is to solve this particular task.
To start, you will need screen installed on the remote unix machine. On Ubunutu 10.04, this should already be installed. Then you simply run screen, run your job and then you can detach and re-attach to your screen session as desired:
ssh remote_machine
apt-get install screen
screen
run your_script
To detach from screen session:screen -d
To re-attach screen session:screen -r
If you have multiple screen sessions, you will have to specify which one when using the -r option, but this is pretty straight forward.
Now you can run your scripts without having them terminated (unless they actually blowup!)
Add new comment