For example, I was running Ubuntu and found an issue with my video card where if I was running a 3d desktop, it would crash if I tried to use a second monitor. The issue was to do with the combined desktop size - so if one monitor is at 1024x600 and the other monitor supports 1920x1200, then the combined desktop size is 2944x1200 (if the monitors are side by side). The issue occurred when the combined width was more than 2048.
So I wrote a script that limited the output on the second monitor to within those limits. The problem was that I couldn't for the life of me figure out how to replace Ubuntu's way of switching displays. When I asked around I got the usual "Why would you want to do that?" soon followed up by "It's a hardware fault". Like I said. Unhelpful. I know it's a fault - that's why I'm trying to fix it.
That was the final straw and I ended up moving away from Ubuntu on my personal computer as a result.
So where is this all leading? There are other bits and pieces in Linux that, although they may be risky and oft times ill advised, they do save A LOT of time. So I've decided to start documenting these bits and pieces.
Hopefully this will help other people out there - and if it doesn't I'll have some notes that will hopefully save me time.
So to add a user non-interactively...
Why is this useful? If you had a list of users you wanted to add to a system, or in my case, needed to write a wrapper around adding a user (in order to make it child friendly for people who shouldn't have to worry about the fact that they're running something other than Windows or OS X), then this comes in really handy.
adduser -p "$( mkpasswd -m SHA-512 $PASSWD )" $USERNAME -G group1,group2
So adduser obviously adds a user. The -p lets you specify a password. Mkpassword creates a hash of the password (basically a one-way algorithm to create a "signature" of the password which is why you normally have to reset a password rather than finding out what the password is).
So to add multiple users, you'd probably put things into a loop - something along the lines of:
exec 4< /path/to/file
while read <&4 ; do
adduser -p "$( mkpasswd -m SHA-512 $( echo $REPLY | cut -f 2 -d " " ))" $( echo $REPLY -f 1 -d " " ) -G $GROUPS
Where the file is a "username password" pair. I haven't actually tested this script so it might not work but it's got the guts at the very least.