For those of you who are accustomed to using the graphical user interfaces (GUI) of desktop operating systems like Microsoft Windows and Mac OS X, you may find the Linux command line to be daunting. Nevertheless, it is a powerful tool that is a must when running a dedicated server.
Even a beginner to Linux dedicated servers can create a shell script. It does not require advanced knowledge of programming, only a willingness to learn. Shell scripts can simplify repetitive tasks and eliminate the need to remember complex command line strings.
The first thing to know about shell scripting is that any line that begins with “#” is considered a “comment” and will not be processed by the shell. To begin writing the script, first create the file:
Next, give it executable permissions:
chmod 755 myfirstscript
Then, open the file in a text editor:
To create a comment, enter a “#” and then type anything after it.
# This is my first shell script.
A script can be as simple as executing several commands. For example:
# This is my first shell script
cp * /hom/user2/files/
chmod 644 *
echo "Transfer complete!"
This basic script will copy the files from one user’s folder to another user’s and then give them read-only permissions. It will then show you the text “Transfer complete!”.
There are many more tasks you can accomplish with simple shell scripting. For a complete tutorial, visit this site.
- How to Send Live Messages to All Shell Users
- How to Create Batches of New Users
- How to Display the Message of the Day to Shell Users
- Server Script Security
- Back to the Basics #11: Secure Shell (SSH)