What if the evolutionary process of human beings was reversed? Yes, we would be apes by now! The point is that it doesn’t make sense to start with the more evolved version of things and then go down to the basics. It actually makes things look a little messy. That’s the thing that happened with me as a blogger. I started blogging about complex things and did not mention about the basics of my work.
But this condition is actually leading to a merge conflict of my notions that I had at the starting of my Outreach Internship and what I have now. I would rather like to present the current version of my notions.
Well, until now, I was trying to get acquainted with Ceph’s internal setup and debugging mechanism (which is completely crucial, if you know what I mean). But in the process, I also came across shell scripting and discovered how powerful it can be. I am still learning new things about it and the way it can be used and it seems as if there’s no limit to it.
One peculiar problem that I came across was substitution of an output of a command into another command. So here’s a command which I had to use to allow ceph mds server to authenticate a user with a particular UID (in my case it was 1000)
./ceph-authtool -C keyring.foo -n client.foo –cap osd ‘allow rw’ –cap mon ‘allow rw’ –cap mds ‘allow rw uid=1000’ –gen-key
You can ignore the details of the command and notice the uid in mds caps.This was supposed to be the UID of the current user. It was easy to determine that using:
But I needed it’s output to be substituted in the mds caps section of the previous command (in the place of 1000). All I did was use $(…) for storing the output generated by my command in a shell variable like this:
But I could not straight away use this variable in the command and run as ceph mds server took the complete string argument as it is. The only method left was to store the complete command as a string, substitute the part where I needed the UID with the variable value and run the command using eval function. Here’s the set of commands:
AUTH_TEMPLATE=’./ceph-authtool -C keyring.foo -n client.foo –cap osd “allow rw” –cap mon “allow rw” –cap mds “allow rw uid=UID” –gen-key’
AUTH=”$(echo $AUTH_TEMPLATE | sed -e ‘s/UID/’$UID’/g’)”
This made things easier for me and helped me in automating my tests.
Okay, so summing up, spending hours running the same set of commands wasted a hell lot of time. Instead, writing it in a single script and running it at once is a lot better option. Definitely try it out if you haven’t yet!