Executing several commands in a text file

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Old 12-30-2015
Executing several commands in a text file

I have a file that has about 3000 commands , listed one below the other. I would like to execute them all in one go. Is there a simpler way to do it - like a batch file processing, than executing one line at a time?
# 2  
Old 12-30-2015

sh scriptname

Now, you have some interesting options. You can log all the output and error to a file:

sh scriptname &> all-output.log

An important option is '-x' which will log each command as it is executed.

sh -x scriptname &> all-output.log

Another interesting option is "-e" which will abort on an error.

sh -e scriptname &> all-output.log

# 3  
Old 01-15-2016
The text file needs to be chmod to executable to run it as suggested.

@otheus you have suggested the all the best possible solutions.

One thing to remember you should know what are the commands doing. example a telnet/ssh or ftp command will have your script (text file) to loose control over the script unless these exit. You need these special commands to be handled specially with 'expect' or with special pipes.

Also if you want them to run as batch not one line at a time. I am assuming you need next command to start along with previous command. Just add a '&' to command. This will run in background.

Do make sure you read up about background commands before going further. You could seriously damage the host if you have multiple commands running in background.

Paste the text file you want make it run as script. That could give more details on how to handle things.
# 4  
Old 03-14-2016
3000 commands in a row could get messy without anyone knowing what is being run. As long as nothing in there violates any sort of NDA etc I'd definitely get a few sets of eyes to go over it in case there are any hidden surprises.

I'm also going to go ahead and say make sure you put comments in the file to describe whats happening etc etc.
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to run commands with pipe from text file? adamlevine Linux 4 05-20-2018 09:35 PM
Executing MQ commands in Perl giridhar276 Shell Programming and Scripting 3 11-27-2016 06:30 PM
Executing multiple commands in a file at same time ragu.selvaraj Shell Programming and Scripting 1 06-13-2013 05:44 AM
Calling a text file while executing a script sunil0106 Shell Programming and Scripting 1 10-31-2012 09:41 PM
executing commands from a file after filtering rbalaj16 Shell Programming and Scripting 1 10-27-2011 08:50 AM
Commands to reorganize a text file gwr Shell Programming and Scripting 11 04-05-2011 10:43 PM
Executing commands Lucky Ali Shell Programming and Scripting 2 09-23-2010 05:04 PM
executing commands over ssh xiamin Shell Programming and Scripting 3 07-28-2010 05:05 AM
Executing commands in different server sravicha Shell Programming and Scripting 1 07-26-2010 02:34 AM
Executing many commands at once kylle345 Shell Programming and Scripting 5 11-19-2009 02:38 PM
How commands are executing ? gsiva Red Hat 3 07-23-2009 12:54 PM
Executing commands after I log off Sergiu-IT UNIX for Dummies Questions & Answers 2 04-01-2005 12:40 PM
Executing mpirun commands tesswulf Shell Programming and Scripting 0 02-11-2004 02:57 AM
FTP - Executing Commands hesmas UNIX for Dummies Questions & Answers 2 02-18-2002 01:18 PM
Executing commands with xargs bmopal UNIX for Dummies Questions & Answers 1 08-13-2001 04:05 PM