How to run a list of commands in linux?

Life Sayings

Member
Registered
Joined
Nov 9, 2013
Messages
59
Points
8
I have a list of commands to backup files, databases or doing some other tasks, I would to run them once

for example

Code:
cd command 1
zip  command 2
copy command 3
...
I heard that it is possible by creating a write a bash script but I don't know how to start. Can you guys shoot me a guide?

Many thanks
 

David Beroff

Well-known member
Registered
Joined
Jun 14, 2016
Messages
1,476
Points
63
I have a list of commands to backup files, databases or doing some other tasks, I would to run them once

for example

Code:
cd command 1
zip  command 2
copy command 3
...
I heard that it is possible by creating a write a bash script but I don't know how to start. Can you guys shoot me a guide?

Many thanks
well if you google learning bash scripts , you will find thousands of tutorials on it. Just go through the tutorials properly.
Interesting question and i do agree with 24x7CSM, i also do a research on Google on how to create a list of commands and run it, tried and it worked.

The first step, you need to have a editor to write content for your file, nano is my first choice.

type:

Code:
nano
Ctrl +O and save with name mycommands.sh

if you don't have nano editor on your hosting, run this "yum install nano" to install it

set permission for this file

Code:
chmod 755 mycommands.sh
run it

Code:
 ./mycommands.sh
you also can run this file by these commands

Code:
bash mycommands.sh
or

Code:
sh mycommands.sh
in mycommands.sh you add these commands to run your list of commands

Code:
#!/bin/bash
# This is your first script
clear 
# put your commands below
cd.. 
zip...
or some commands here.
echo "Done"
Hope it helps!
 

serverbundle

Member
Registered
Joined
Oct 2, 2016
Messages
62
Points
0
Bash is certainly to do it however if you are good in any other scripting language for ex. Ruby, Python or PHP even they have built-in functions which can be used to exec system commands.
 
Recommended Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top