Linux basic scripting (similar to batch script in Windows)

I have to build a Buch of machines in work and have 30 odd linux commands to run. We use CentOS and I'm trying to find out if I can automate the process a little by having a script that cycles through the commands so I don't have to keep copy and pasting them.

I'm new to linux and could write a batch script in Windows but don't know what the linux equivalent is to search in google.
I would like to keep each command on its own line in a file, then have a window that basically asks the user "do you want to run this command xxxxxxxxxxx"
The user then presses "y" and it goes onto the next one etc etc.

Is this easy to do in linux?
Who is Participating?
Travis MartinezConnect With a Mentor Smoke JumperCommented:
Are you more familiar with PowerShell?  You can install the shell as a package on the base CentOS image.  Not sure if that would help put the scripting knowledge back in the wheelhouse you're familiar with:
Travis MartinezSmoke JumperCommented:
It is rather easy with the "read" statement in your script.  This is kind of difficult to expand upon without further information.
Travis MartinezSmoke JumperCommented:
Here's a basic example and output:

$ while [ $x -eq 1 ]
> do
> echo "hello world /n"
> echo "would you like to continue (y/n)"
> read answer
> if [ "$answer" = n ]
> then $((x++))
> fi
> done
hello world /n
would you like to continue (y/n)
hello world /n
would you like to continue (y/n)
hello world /n
would you like to continue (y/n)
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

As Travis pointed out with an example, the answer is yes.

There are many possibilities, but lack of information on what the tasks are, it is hard to answer
The short answer is yes, sh, bash, zsh, ksh, csh are the basic scripting somewhat equivalent on a level to batch scripting since they rely on the execution of other commands to do things.
There are other scripting option as does Windows that are more robust in the same comparison vbscript, powershell on Windows such as perl, TCl/ti, Python, php.....

The optimal choice depends on what the tasks are.
Getting user input is the least as read in the example provides, once you get the user input what then?

The shell, batch scripting requires that you harness the response from one command and can pass it to the next one, the more robust scripting avail the option to handle the flow in a more seamless wait, less probe to typo, or oversight that while you expect the prior respinse to be passed to the next command..

If the task is simple, execute the following commands in a sequence without interdependency I.e. Execution of this command does not depend on the execution of the prior.
PJ0302917Author Commented:
Hi guys, thanks for looking into my question and helping me out. I've not used Linux much and a Shell Script seems to be the way to go.
As far as additional details go, I'd like to code the following.
1) A master script which the user runs and interacts with
2) Configuration files which contain commands such as make directory, copy files, change privileges etc. There could be a number of configuration files but only one master script.

So the master script will start up and list all the configuration files found in its local directory. User inputs number 4 to load configuration file 4.

I guess the master script will use the "read" command to iterate each line of the configuration file and execute the command.

In the master script the user is asked if they want to run "mkdir Test_Files"   (this is the first line of Configuration File 4)
User presses 'Y'
master script then states "mkdir Test_Files successful"
master script then asks if they want to run "cd Test_Files"    (this is the second line of Configuration File 4)
User presses 'Y' etc etc
arnoldConnect With a Mentor Commented:
Where does this master script create files?
Issue, to create thing outside the user's home dir will require the script to run with elevated rights.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.