How to run linux scripts

Scripts can be defined as a sequence of commands that are stored inside a file and are usually executed in order to automate certain tasks. In the following minutes I’m gonna show you how to run linux scripts from the shell.

In the BASH environment you can find many types of scripts. Depending on the user needs you can find BASH, Python, Perl or other type of scripts.

In some cases they might have an extension like .sh, .bsh, or .py, however this is not a rule. In Linux, files don’t need to have an extension, but they are required to have an shebang.

The shebang is the first line in a script which tells the shell what program to interpret the script with, when executed.

Here’s an example:

~ # more /root/

As you can see, the first line in the script tells us that this is a BASH script.

So, how can we run a script ?

First you need to check the permissions of the script:

~ # ls -l /root/
-r--r--r   1 root     root          156 Jun  1 20:12 /root/

In order to execute a script, the user under which the script needs to be executed has to have execution permissions, and the above one doesn’t have that permissions and this is how you can fix it:

chmod + x ./

No check the permissions again:

~ # ls -l /root/
-rwxrwxrwx   1 root     root          156 Jun  1 20:12 /root/

The permissions are ok now.

Now you can run the script by typing:

~ # ./

Alternatively, you can run the same script with it’s absolute path:

~ # /root/

A python script can be run like this:

~ # python
Usage: server [options]

Test for SSL heartbeat vulnerability (CVE-2014-0160)

  -h, --help            show this help message and exit
  -p PORT, --port=PORT  TCP port to test (default: 443)

~ #

run linux script







In Perl:
Hello world!