I am a junior sys admin. Reason I'm asking this question is because we don't have a senior sys-admin here who is proficient with scripting. Senior guys are at the head office and too busy for something like this.

My scenario is this. I have to run a three scripts often, for deploying an application. The scripts were made by a senior sys-admin. Generally things go smoothly with them and no errors. But, I have to babysit them for input. :(

During parts of these scripts, there's parts when I have to enter yes or no. My answers never change, unless the previous part fails, then I select no, and it says 'build failed.'

There's basically these parts that I run:

1 - SSH into a deployment server

2 - edit a small string in an file (which specifies a server specific information)

3 - run script A, which basically scps all the files from the deployment to the target server. The only input I have to give here, is at the end. It asks if the correct date is shown from the target, if I say yes, the build is successful.

4 - run script B also from deployment server, which needs some specific information, for example like:

./scriptB X Y Z where X, Y, Z change depend on target server information.

Script B has some questions like 'do you want to do this or drop this', the answers stay the same. Also sometimes there's an ANT bug so it wants me to hit '1' until the script continues.

5 - run script C, which is very similar to script B. At one point though, it is about to run a particular step, and I must manually hit 'control c' to exit out.

I'm a noob at scripting, but if someone could tell me or give me an idea how I could do this that would be great. I thought maybe I could use expect.

Even better, would be if I could just click some EXE on my Windows laptop, and it does everything. Is that even possible?

  • Please add the scripts – 030 Feb 26 '15 at 18:53
  • I would love to, is there a way around this? Just a little paranoid because I'm not sure corporate policy would allow this...I could paste an excerpt. – 2legit2quit Feb 26 '15 at 21:14

It sounds like you should look at two things:

  1. Editing the old script to either do some of the checks automatically (the timestamp one for exapmle), or remove the prompts (look for read commands) and answer with defaults.
  2. Using a tool designed for exactly this task, such as Ansible.

If you want to learn something new and improve your sysadmin CV, I'd look at the second option, although the first should work fine in the short term!

If you start with the first option I mentioned, try and make Script A not require a prompt - use the date function to get the current date maybe, and do the check automatically. If it's a date you're comparing from the files you've just copied, you should be able to use tools such as find or ls to get that info.

Running Script C, it should be trivial to put in an exit command where you would normally hit CtrlC.

Above all, remember to test this on non-critical boxes! You don't want to barf the production setup while you hack old scripts...

  • Thanks so much. I have heard of Ansible. But I have never used it. Is it use bash? Are there any good bash books you could recommend me? It sounds like Ansible could do what I want. For example, I could make some different server configs (i.e. for different parameters like province), and push them out when needed right? – 2legit2quit Feb 26 '15 at 21:12
  • It communicates over SSH and runs remote commands as you would from the shell (with some small differences I imagine), so yes, it uses bash. Books is a very broad topic, it depends on your level, what you're trying to achieve, etc. etc. Ansible uses playbooks to define scenarios - I'm not that familiar with it myself but others swear by it. – shearn89 Feb 27 '15 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.