Linux and Windows scripting languages

Source: Internet
Author: User
Tags perl script

This article was translated from Isystemadmin, "List of Popular Scripting Languages for Linux and Windows."

A system administrator with scripting Knowledge has a distinct distinction from other system administrators. A script is an art created by a "system administrator". This art requires knowledge of the system itself, the syntax of system administration commands, programming and algorithmic knowledge, and at least one scripting language. There are many choices for a system administrator to write scripts, each with its own unique syntax and advantages. There are few similarities between scripting languages, but they are not as difficult to read as the alien language. Scripting languages can be used both to manage systems and for web development. Server-based and client-based scripting languages are rare. The client scripting language is mostly used to display content and interact with users in a browser. Server-side scripting languages are typically used to manage systems or Web services. In this article, we will focus only on those scripting languages that are used for system administration. Let's get started!

about what the script should know:

• The script should be executed as a standalone command, or it can be called using a script-language binary file under the Terminal command-line interface.

• If it is an executable script, you should write the following line of special code at the beginning:

1 #!/path/of/the/cli

such as Bash

1 #!/bin/bash

Or Perl.

1 #!/usr/bin/perl

‘#!’ This symbol represents the program that needs to be called to execute the script.

Bash

In the Linux and Unix worlds, the largest number of bash scripts. As we have mentioned in many articles, Bash is also the most popular of all. Basically, bash is a command-line shell with an explanatory function. It can be used as a programming and meets most basic programming needs. You do not need to declare or know the type of a variable before using it. The downside is that there are no other libraries available to use bash. You can use only /bin/bash (or /bin/sh). When you declare a variable, you do not need to use the $ symbol in front, but you need to precede it with $ to indicate that it is a "variable". Bash is very easy to write, Linux, UNIX, and Windows with Cywin programs with bash. If you are a system administrator but do not bash script programming, you'd better start learning right away. The article "10 Best Books for system administrators" lists a number of good reference books. Here's a simple bash script.

12345678910111213 #!/bin/bashUSER=$1 echo "Adding User $USER in group users..." /usr/sbin/useradd -g users $USER if [ $? == 0 ]; then        /usr/bin/passwd $USERelse        echo"Sorry, User addition failed"fi

Perl

Basically, Perl can be seen as a complete programming language (Turing) on UNIX and Windows systems. The meaning of Perl is the practical Report extraction language (practical Extraction and Language). Perl is a general-purpose programming language that was originally developed for word processing and is now used in a wide range of applications, including systems management, web development, network programming, and even GUI development.

It has the advantage of being easy to use and supporting both process-oriented and object-oriented programming. Perl is modular and easy to call third-party modules. Although the goal of the design is Turing's complete programming language, Perl has been used to write system administration scripts since 1993. Perl supports both compilation and interpretation, so Perl is more secure than bash scripts. When an error occurs, the bash script does not know; however, if any errors occur during the compilation process, Perl refuses to start execution. A small Perl script will allow you to experience the style of the Perl language. #之后的内容是注释. This script creates an array of 1000 random numbers, each of which contains 16 numbers:

1234567891011121314 #!/usr/bin/perlmy @numbers;srand (time);for ($i=0; $i<1000; $i++){$a=int 10000000000*rand();$b=int 10000000000*rand();$c = $a . $b;push @numbers,substr($c,0,16)."\n";}print @numbers;

Php

As you know, PHP is often used as a Web site development, but it can also perform system administration tasks like Perl. That's why many system administrators use PHP to complete cron tasks and other scripting work. While similar to Perl, PHP's goal is to generate HTML standard output. Typically it will be embedded in the Web server program to run. The command-line version of PHP supports scripted programming. Similar to the Perl example above, the PHP script for the same functionality is as follows:

1234567891011121314151617181920212223 #!/usr/bin/phpfunction make_seed(){list($usec, $sec) = explode(‘ ‘, microtime());return (float) $sec + ((float) $usec * 100000);}srand (make_seed());for ($i=0; $i<1000; $i++){$a=rand(1000000000,9999999999);$b=rand(1000000000,9999999999);$c = $a . $b;$numbers[]=substr($c,0,16);}for ($i=0; $i<1000;$i++)echo "$numbers[$i]\n";

Python

Obviously, we're talking about scripting languages, not some kind of animal in the Amazon jungle. Python is a general-purpose, high-level programming language that emphasizes the readability of code. Python's syntax is simple and expressive. Like Perl, Python also has a lot of extension libraries. Although Python has the ability to function programmatically, most of the time it is considered an object-oriented language. In web development, Python was used to develop the MOD_WSGI module for the Apache project. Today, most Linux and Unix distributions contain Python, and many of the system tools used as scripting languages are developed in Python. Python also supports writing code for the GUI environment. Here's a simple Python code:

123456789101112131415 health = 10trolls = 0damage = 3while health >0:        #!= 0:trolls += 1health = health - damageprint " " \"but takes", damage, "damage points.\n"print " ", trolls, "trolls."

Sed

Sed is a UNIX text parsing tool that provides a programming language that can be used to parse and transform text. SED is the abbreviation for Stream editor, which is basically a text editor that runs fast. SED does not provide any interactive environment for file editing. It reads the content row by line, executes the command-line specified action on the read content, which is the SED script, and then outputs the execution result. You can quickly perform text operations on files with SED. Perl has recently been used to deal with the same work, but there are still situations that require the expert system administrator to quickly resolve tasks using SED. The following is a simple example:

1 $ sed-e ‘s/foo/bar/g‘myfile.txt

This command will look up all foo in the MyFile.txt file and replace it with bar and output the result to the screen. The main command of SED is ' s/foo/bar/g ', which is also supported in the interactive editing mode of VI or VIM.

In addition to what this article describes, there are many other scripting languages like Ruby, VBScript, Java script, JScript, TCL, AppleScript, and Falcon, among others. The purpose of this article is to introduce the scripting languages that are commonly used in system administration, and hopefully you will be familiar with them and improve your productivity.

English original Isystemadmin compilation: Bole online – Tang Yuhua

Linux and Windows scripting languages

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.