Skip to content

Instantly share code, notes, and snippets.

@laderast
Last active November 19, 2016 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laderast/119eff812ce76081ba5e941f1054f3a1 to your computer and use it in GitHub Desktop.
Save laderast/119eff812ce76081ba5e941f1054f3a1 to your computer and use it in GitHub Desktop.
stupid-unix-tricks.R

##SSH Keys

SSH Keys simplify logging into a remote server for automated processes. Basically, it lets you automate any remote operation that requires a login/password combo.

Caveat: SSH Keys are on a single client/server basis and are one way. This means for each machine pairing and each direction, you will need to generate a set of SSH Keys.

We usually use them only on a one way basis.

##Generating SSH Keys

To generate an SSH Key between a server and your machine, you need to first generate the key on your home machine/account.

ssh-keygen -t rsa

You'll then be asked where you want to store your keys.

Then you can use ssh-copy-id to copy the public key onto your remote machine.

ssh-copy-id user@123.45.56.78

You'll be asked for login information for the remote machine.

Anytime you want to do anything on the remote machine, you won't have to login.

##For more info

https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2

##rsync

rsync is an extremely useful utility for transferring files and syncing two folders. Unlike FTP, rsync can detect differences between two file

rsync can also play nicely with Box (the OHSU) with a little tweaking.

##What can rsync do for you?

  • keep two folders in sync on the same machine (very useful for development/deployment instances)
  • keep two folders in sync on different machines
  • synchronize your data to file services such as Box

##rsync-ing between two folders on the same machine

rsync -avr -delete /home/USERNAME/analysisResults/QC/ /home/laderast/CyTOFApp/data/

##Lots of options

##rsync-ing between remote machines

To synchronize between two different folders, you can add your user/machine combo to the beginning of the target folder:

rsync -a ~/CyTOFApp USERNAME@stuff.ohsu.edu:/home/groups/Shiny/CyTOFApp/

##Mounting Box.com

This was a very helpful tutorial here. http://aarongriffith.net/2014/08/mount-box-cloud-storage-in-ubuntu/

##cron

cron is a job scheduler that allows you to automate processes at specific times of day. Much of linux depends on cron running in the background.

It basically reads the required jobs from a schedule called a crontab.

##crontab

What makes it useful for you is that every user account has its own crontab. You're free to modify this crontab to automate nightly jobs.

##The many uses of crontabs

http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples

##Building crontab entries

This is a very useful GUI interface that you can use to populate your crontab:

http://www.corntab.com

##Putting it all together

You can set up SSH keys for your machine and exacloud. By scheduling a cron job, you can use rsync folders on a nightly basis, or do nightly git commits, or run processor heavy jobs when a machine is more likely to be free.

The sky is the limit. Use this power wisely.

##screen/tmux

screen is an extremely useful utility for a number of reasons. The number one reason I use screen is for running a background process that will run even when you log out. tmux (terminal multiplexer) is similar, but also allows you to open multiple screens.

##.bashrc, .bash_profile, .profile Tricks

##Pipes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment