Fun with Linux/Mac

Doing passwords in sh files to automate the basics with scp…

It’s things like this that, while certainly not very intuitive, make nix so much better than windows.

I wanted to back up my PostgreSql db on my production box everyday to my local dev box and do it via a one command. With a bit of google’ing this was pretty simple.

From this post and this post I hobbled together this procedure. Read those posts if you want to understand this stuff better – this is mostly just notes for me – because I’ll forget and those posts might go down.

We’ll allow our local box (called wiseleyb@mybox) to connect to our production box (called
In /home/wiseleyb on the computer mybox – generate a key:

wiseleyb@mybox:~>ssh-keygen -t rsa

Hit enter for all the prompts
It should have created a file /home/wiseleyb/.ssh/

Now – copy that up to

wiseleyb@mybox:~>scp .ssh/

SSH into

password:>cd .ssh>cat >> authorized_keys>exit

You should now be able to ssh and scp without passwords… give it a try…

wiseleyb@mybox:~>ssh ls

You should see the directory listing.

Now – you just need to write a simple sh file to automate this…

   DATE=$(date +%b%d)
   ssh pg_dump -Fc -f prodboxdb_$DATE.db prodboxdb_production
   scp$DATE.db /home/wiseleyb/prodbox_databases/.
wiseleyb@mybox:~>chmod 755

Pretty simple once you get the key stuff working…

Try doing that in windows with SqlServer and vbscript and posting anything less than a book about how you did it. :)

1 Comment

mattNovember 15th, 2006 at 11:31 am

A stickler will point out that Mac OS isn’t based on Linux – it’s a BSD based operating system.