Linux Journal Scripting Games?
For those of you who were unhappy that Script Frenzy was not about writing scripts but about writing...well...scripts, here is something to entertain you...The 2010 Scripting Guy Games! Huh? Windows? Um...
OK, yes the Scripting Guy Games are for Windows. But what if we did it for Linux. What sort of meaty script challenge could we come up with? Certainly something more challenging than determining the time or reading the registry. Here are some thoughts, with apologies to the Scripting Guy(s) for stealing their format.
Day 1: Beginner: Create a script to add a user to the system, provision their mail, IM, shares and home page.
Day 1: Advanced: Create a script to add a new system to the infrastructure, provision it and bring it on line without manual configuration.
Day 2: Beginner: Create a script to deprovision a departing user account, back up their files and move them off into storage.
Day 2: Advanced: Create a script to migrate an high-availability web cluster with MySQL database to new hardware, provisioned using the script from Day 1.
All four of these tasks were ones that I got hit with about two days into a job several years ago. The fun part was that we had to use basic shell commands. We did not have perl installed on the systems for security reasons, and we did not have ruby, or python or any of those wonderful tools. Just a bare bones installation of the kernel and bash (although feel free to use your shell of choice...ksh anyone?) - the tools needed to do the job at hand.
So, what do you think? Are you up to the challenge? Maybe we should set up a Scripting Gurus help and trade area on the site! Hmm...did I just hear our beloved webmistress whimper?
David Lane, KG4GIY is a member of Linux Journal's Editorial Advisory Panel and the Control Op for Linux Journal's Virtual Ham Shack
Trending Topics
| Calculating Day of the Week | May 30, 2012 |
| Hack and / - Password Cracking with GPUs, Part II: Get Cracking | May 29, 2012 |
| Networking Poll | May 29, 2012 |
| OpenLDAP Everywhere Reloaded, Part I | May 23, 2012 |
| Chemistry the Gromacs Way | May 21, 2012 |
| Make TV Awesome with Bluecop | May 16, 2012 |
- Hack and / - Temper Temper
- Calculating Day of the Week
- Hack and / - Password Cracking with GPUs, Part II: Get Cracking
- Validate an E-Mail Address with PHP, the Right Way
- OpenLDAP Everywhere Reloaded, Part I
- RSS Feeds
- Hack and / - Password Cracking with GPUs, Part I: the Setup
- Networking Poll
- Tales From the Server Room: Zoning Out
- Boot with GRUB
- Really nice :-)
Something
3 hours 52 min ago - Have you experimented with
3 hours 54 min ago - Awesome..
4 hours 15 min ago - Good One..
4 hours 34 min ago - Nice One...
4 hours 38 min ago - very good web: ---(
4 hours 41 min ago - very good web: ---(
4 hours 48 min ago - very good web: ---(
4 hours 50 min ago - very good web: ---(
4 hours 54 min ago - very good web: ---(
4 hours 56 min ago





Comments
A couple challenges
Here's one that's almost as trivial as the Scripting Guy's exercises.
Beginner: Take as input a list of tab-separated values. One column of this input will be numeric. Sort the list by the numeric column in ascending value and output the sorted list.
Example input:
Example output:
Advanced: Same task, but the number of numeric columns is unknown. You may assume that each column contains either text or numbers, but not a mix of both (unless you go for the third extra points goal). The script must exit with an error if no numeric column is found. If multiple numeric columns exist, prompt the user for which one to sort by.
This one is more involved, but accomplishes a more useful task.
Beginner: You have a directory hierarchy full of files that may have odd filenames (mixed case, spaces and other special characters). Create a script to copy these files to another location while maintaining the directory structure, changing all names so they only use the letters a through z (lowercase), numerals, period, underscore, and hyphen. The first character of any filename or path component may not be a hyphen. The script must avoid filename collisions (e.g., if the original directory contains foo.txt and FOO.TXT, these files must both end up in the new hierarchy and have different names).
Advanced: Same task, with the added constraint that the script must maintain the file extension (e.g., foo.txt and FOO.TXT can become foo.txt and foo_2.txt, but not foo.txt and foo.txt_2). Also, generate a list on standard output of the old filenames mapped to the new ones.
I keep meaning to try these.
I keep meaning to try these. I know how I would go about doing them. I love awk so I'd do something like this for the first beginners challenge (off the top of my head)...
#! /bin/bash awk '{print $2, $1, $3}' inputfile | \ sort | \ awk '{printf("%s\t%s\t%s\n", $2, $1, $3)}'Re: I keep meaning to try these.
That's very close to working on the example. But awk by default splits on any whitespace, not just tabs, so "passion fruit" would be split into two fields (hint: check out the FS variable or -F option).
Actually, you could rewrite your script to remove awk entirely if you used the -k option of sort.
However, one thing I didn't make explicit (how tricky of me :-) in describing the first exercise is that you don't know which column is the numeric one. Here's another possible input:
And the correct output:
Your script needs to somehow figure out which column is the numeric one. I hadn't thought of using awk to do this, but since you brought it up, I think it would work nicely for that job. Happy scripting!
(P.S. I don't know how long comments stay open, so if you want to reach me directly you can do so at vkochend at nyx.net).
i would love that, but i
i would love that, but i would go with different challenges
Challenges
I just pulled something off the top of my head as the challenge...that being said, what sort of challenges would you like to see?
David Lane, KG4GIY is a member of Linux Journal's Editorial Advisory Panel and the Control Op for Linux Journal's Virtual Ham Shack
well, your ideas seem to be
well, your ideas seem to be centered towards setting up a network. every network is different, therefore, it would be difficult to judge scripts based on a specific network. i would also go with something other than setup. but that's just my opinion.
I am up for that :)
I am up for that :)
Sounds like a great idea
This sounds like the kind of thing I'd really enjoy. Be very interested in getting involved if something like this came about.
why?
why? there are literally hundreds of well established sites doing this already. support them rather than invent the wheel again.
Because...
it would be fun.
If you don't agree,then...
Sounds like fun
Sounds like heaps of fun.
I really don't need another distraction from my uni assignments at the moment, which have their own programming involved, but I'm definitely up for some scripting :-).
--
Regards,
Matthew Cengia
This would be awsome. I'm no
This would be awsome. I'm no guru but I'd love to help.