Basics of Shell Scripting
A Unix shell is a command-line interpreter or shell that provides a
traditional user interface for the Unix operating system and for
Unix-like systems. Users direct the operation of the computer by
entering commands as text for a command line interpreter to
execute or by creating text scripts of one or more such commands.Shell scripting plays a major role in pentesting.
To create a shell script, we need to start with a text editor. You can use any of the text editors in Linux including vi,sublime,atom etc but I prefer using Sublime text editor.
Next, we enter echo, a command in Linux that tells the system to print in the terminal. In this case, we want the system to echo back to us “Hello world”.
- echo “Hello world”
Save it and close the text editor
Next we set the executable permission,using CHMOD command.When we create a file, it’s not necessarily executable, not even by us, the owner.Now we change the permission as
- chmod +x filename.sh
where + refers the addition of permission and x refers the executable permission
To run our simple script, we simply type:
- ./filename.sh
By this we can add several linux commands to automate the daily or complex tasks like backup
Some Linux commands:
- mv target destination —Moving a file to another location
- cp target destination —Copying a file to another location
- Chmod option filename —Changing file permissions
- cat filename —displaying the contents of the file
- More — Does the same thing as cat
- TOP — Displays all the running processes
- Who–Displays current logged users
- Whoami–Displays the current user name
- PS–Displays the user processes
- SU–Switches the current user to superuser account