Use curl to upload files and post other data

This should’ve been more obvious to me but it did take a few minutes of playing around and reading the manual to get this right. I wanted to post data to a api using curl and one of the items was a file upload and another was a simple field/value.

To upload a file via curl:

curl -X POST -F "image=@profile.jpg"

In php this will give you the profile.jpg in the $_FILES[‘image’], now to add additional field values you just add additional -F arguments like this:

curl -X POST -F "image=@profile.jpg" -F "phone=1234567890"

Escape SSH Sessions

I’ve seen a few blog posts around outlining this but I always seem to forget and then take a few minutes searching for it again so I thought I’d post it here just so I can always find it again.

When you have an ssh session open in your terminal or in screen and you need to hop out of it or you need to kill a hung session you can do it with the ~ hotkey.

*Press return once first before hitting the hotkey to start a fresh entry, even if you enter something and press backspace to clear it you still need to hit return once first.

Kill Session:


Suspend Session to Background:




sudo: unable to resolve host

There was a nagging issue I had with a dev server where any user that used sudo it would produce the error:

sudo: unable to resolve host

The probelm: the hostname had an incorrect line ending in the file /etc/hostname.

The solution: reset the fileformat for the file back to unix. I did this with vim.

sudo vi /etc/hostname
:set ff=unix

automysqlbackup/mysqldump of Views on a MySQL Replication/Slave machine

Today an error appeared in my inbox from automysqlbackup indicating there was an issue with the backups being run from a slave machine that is used strictly for running backups.

mysqldump: Got error: 1045: Access denied for user 'backup'@'localhost' (using password: YES) when using LOCK TABLES

Unfortunately this was not overly useful.

I tracked down the particular database that was causing problems and received a new error message that was getting a lot more useful:

mysqldump: Couldn't execute 'show create table `REPORT`': SHOW VIEW command denied to user 'backup'@'localhost' for table 'REPORT' (1142)

I’m no expert but what this is roughly saying is that the ‘backup’ user @ ‘localhost’ does not have the ‘SHOW VIEW’ privileges and because ‘REPORT’ is a view and not an actual table and my backup user typically only has ‘SELECT’ this is where we were failing. Seems simple enough assign the user the correct privileges and we should be good to go.

Not so fast. I ran into one more error attempting to access this view:

mysqldump: Got error: 1449: The user specified as a definer('root'@'%') does not exist

Once again I’m far from an export on this but my understanding is that the view was created or defined by a particular user known as the definer and because this is a slave machine the user that created the view was only on the master server (as the mysql db is not replicated over) and not on the slave machine therefore the view was inaccessible.

I created the correct user (exact same username @ hostname) on the slave machine and now our backup user with correct privileges was able to read the view and perform the backup as expected.


Today I loaded up one of my haproxy instances on amazon ec2 and I decided it was a good idea to take a quick peak at the haproxy.log to be sure it booted it correctly etc… I saw a ton of entries (several per second) being added to the log that looked something like this:

Jul 21 09:44:19 localhost haproxy[3536]: [21/Jul/2011:09:44:19.707] webserver webserver/ -1/-1/-1/-1/0 400 0 - - SC-- 1998/0/0/0/0 0/0 ""

I ran a quick check on the config file to be sure it was all good and sure enough the address for the webserver returned the error “Invalid server name: ‘'”. Obviously that server no longer reponds, in this case it was a server that we no longer were using and my config on this machine was out of date, I updated the config, (re-ran the check) and restarted. Good to go.