Posts: 17
Joined: Thu May 10, 2012 12:12 pm

Help: Taking a shell script to the next level

Tue Mar 25, 2014 10:28 am


I need some advice. I'm a linux network geek, not a programmer by trade. I have written a bunch of shell script that carry out network testing* that I want to take to the "next level" and ultimately make available to a public audience. I'm not familiar with any particular higher level language so have no preferences.

The network testing scripts, in summary, cycle through if/else/while/then loops of parameters (BW, packet size, IP address), SSH to a remote host, run a remote command such as ping, mtr or iperf then parse the results from the command into a nice looking table in a text file.

So... by "next level" I mean:
- Presenting a more-interactive UI to the user instead of a list of questions to grab variables, enable/disable the various tests from running.
- Improved error-checking over the data the user enters e.g. an IP address is actually in IP address format.
- Improved error-checking over the remote commands being run e.g. don't halt if the remote host isn't available via SSH, confirm that the remote command ran successfully or not.

The help I'm looking for is advice on a language (yeah, I know I probably just started a religious war) and document resources that can help me convert the variable gathering, while/then, if/else loops & ssh remote commands in my shell scripts into that language.

I'm also open to advice that sticking with shell is ok and that I'm overlooking some of the more obscure features of the linux command line that can improve them.


*-If you were at the Cambridge Raspberry Jam then yes, that was me in the final talk of the day, talking inexpertly about testing mobile & Wi-Fi networks via the Raspberry Pi.

Posts: 84
Joined: Fri Jan 04, 2013 1:30 pm

Re: Help: Taking a shell script to the next level

Tue Mar 25, 2014 3:22 pm

You have two main options; either add interactivity to the shell script (check out zenity for example) or learn a high-level language such as Python. There are many books on Python, some specific to the Raspberry Pi. No doubt there will be a lot of recommendations.

User avatar
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: Help: Taking a shell script to the next level

Tue Mar 25, 2014 3:27 pm

My personal preference would be python and a sqlite database. Anything written for sqlite would be pretty easy to port to MySQL or PostgreSQL.

I'd actually be willing to help with this if it has interesting features. For some boilerplate sqlite/python functions, scroll to the Database Utilities portion at the bottom here: https://github.com/iinnovations/iicontr ... d/pilib.py

Drop me PM or some more details here if you like.

CuPID Controls :: Open Source browser-based sensor and device control

User avatar
Posts: 8
Joined: Wed Nov 06, 2013 4:33 pm

Re: Help: Taking a shell script to the next level

Fri Apr 04, 2014 3:53 pm

I like your comment about starting a religious war. Python seems to be the default option with the Pi and for me, so far, the simplest to understand for a non-programmer. I am wanting to learn some more about networking options as I would like to have a household intranet without having to use an internet connection - a requirement at present with the limited tools I have available.
best of luck
I seemed to have earned a reputation as being somewhat less than intact, both hardware and software tests are, as yet, inconclusive as to the reason for this. Syntax errors in the original programming are perhaps the most likely cause.

Posts: 22
Joined: Thu Jul 11, 2013 8:11 am

Re: Help: Taking a shell script to the next level

Thu Apr 17, 2014 5:41 pm

I think you can do everything stated with shell. How about skipping the interactive UI altogether and reading from a file the parameters you need? If multiple test, then maybe sections in the file and only run the tests that are specified.

Return to “General programming discussion”