Skip to main content

Posts

Showing posts with the label shell

Working with Regular Expressions

Introduction Regular expressions are a way of manipulating text by using character strings and metacharacters. They are often used by programmers, but can also be used in shell commands and in some programs (e.g. vi and other text editors). The examples that follow are mainly based upon the regular expression format used by perl. They are also the same as those available in PHP using the preg regular expression functions. Some programs / languages may use different syntax or meta-characters but the general concept is the same. Getting started Regular expressions can initially be compared with wild-characters that you may already be familiar with, but regular expressions are much more powerful. For example most people are familiar with the ? and * when used on the command line to mean: match any single character, and match any number of characters, respectively. To match a using a regular expression the expression is first contained within forward slashes. For example: ...

Unix/Linux Variables

 UNIX Variables Variables are a way of passing information from the shell to programs when you run them. Programs look "in the environment" for particular variables and if they are found will use the values stored. Some are set by the system, others by you, yet others by the shell, or any program that loads another program. Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, environment variables have UPPER CASE and shell variables have lower case names.  Environment Variables An example of an environment variable is the OSTYPE variable. The value of this is the current operating system you are using. Type % echo $OSTYPE More examples of environme...

How to keep a script running even after logging out of the system

There are times when we need to do some job or run some script which takes a lot of time. During this the connection can get aborted which results in the job getting killed. There is simple solution for this, Use NOHUP. The command syntax is easy:- nohup <command>  & here  <command> is the command or script you're running. An & is need to put the command in the background as nohup doesn't do this itself. For example, when you log-in to the remote server using ssh. # ssh user@remoteserver now you want to run a backup script rsync_script.sh  which takes a long time, then you can run, # nohup rsync_script.sh & you can now logout from the terminal & the script will continue to run until its completed.