LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Scripting in genral? (http://www.linuxquestions.org/questions/programming-9/scripting-in-genral-4175438242/)

peacepanda 11-22-2012 03:12 AM

Scripting in genral?
 
I need some guidelines to write a shell script that has following problem statement.Please suggest.

Need to write a shell script that will go to list of servers.
Go into the mentioned folders and check for a particular string and ask from the user if he wants to change a occurence with anoter string.

Thanks,
Ajit

salasi 11-22-2012 03:25 AM

Guidelines?
  • Document well; you will be surprised how much you will have forgotten in only six months
  • Define the problem clearly
  • For the cases in which you can't define the problem clearly, define the things that you can't define
  • You'll want to test - try to define the test cases in advance of writing anything, and then when you have written something revisit that definition of test cases
  • Think about what options you'll want the script to have; the first thing is to get the 'main option' working, but think about what extra options could be helpful and how the user interface might work
  • Post your initial code on this website - you'll get helpful comments

Good luck!

TB0ne 11-22-2012 09:09 AM

Quote:

Originally Posted by peacepanda (Post 4834586)
I need some guidelines to write a shell script that has following problem statement.Please suggest.
Need to write a shell script that will go to list of servers.
Go into the mentioned folders and check for a particular string and ask from the user if he wants to change a occurence with anoter string.

We'll be glad to help....so post what you've written/tried so far, and where you're stuck. However, we're not going to write scripts for you.

Have you looked at the bash scripting tutorials??
http://tldp.org/LDP/abs/html/

Running an interactive command on another server is going to be a challenge. A tool like puppet or fanout may already do what you're looking for.

theNbomr 11-22-2012 09:18 PM

My first guideline is to clearly define and state what you really want. Your problem description leaves a lot of gaps. For instance: 'a shell script that will go to list of servers' Go to? What do you mean by 'go to' a server? Make a network connection? What kind of servers? File servers? Web servers? Database servers? Are they on the local host, or out there somewhere on a network?
Another vagary: 'list of servers'. Where is the list? In a file? To be provided from a user? In a shell variable? It is necessary to know this in order for the script to read and parse the list.

You need to recognize that no one reading your description here knows anything whatsoever about the problem. Nothing. Everything has to be spelled out unambiguously. The benefit of doing that will be that it allows you to really think about the elements of the problem in terms that will be part of the solution. So, when someone provides a suggestion, or asks for more information, you will already be thinking in similar terms. It is a bit like the concept that the best way to learn some subject is to teach it. Teach us the details of the problem, and by doing so, start learning about the solution.

--- rod.

salasi 11-23-2012 03:25 AM

Thanks to the theNbomr for that; that is exactly the kind of thing that I had in mind.

You'll be surprised at the extent to which having to state the requirements makes you go through an '...I thought the problem was defined, but now I realise that I have no idea about this aspect..' cycle.

One important aspect that hasn't been mentioned so far is the response of the server: what is intended to happen if a server is down, the network connection is not working or the server only responds slowly? You have to think through the bad stuff that can happen and ensure that you do something sensible (and what qualifies as 'sensible' is heavily dependant on the context stuff that you've spent little time telling us).


All times are GMT -5. The time now is 05:05 PM.