Skip to main content

Posts

Showing posts from 2017

Special Permissions

Sticky Bit The sticky bit is used to indicate special permissions for files and directories. If a directory with sticky bit enabled, will restricts deletion of file inside it. It can be removed by root, owner of file or who have write permission on it. This is useful for publicly accessible directories like /tmp. Implementation of Sticky bit on file: Method 1: # chmod +t tecadmin.txt # ls -l tecadmin.txt -rw-r--r- T 1 root root 0 Mar  8 02:06 tecadmin.txt Mothod 2: # chmod 1777 tecadmin.txt # ls -l tecadmin.txt -rwxrwxrw t 1 root root 0 Mar  8 02:06 tecadmin.txt In above output it showing sticky bit is set with character t or T in permissions filed. Small t represent that execute permission also enable and capital T represent that execute permission are not enabled. SUID ( setuid ) If SUID bit is set on a file and a user executed it. The process will have the same rights as the owner of the file being executed. For example:  passwd  command have

File permissions

Linux permissions are basically split into two areas. These are: • File ownership • File access permissions Every file has an owner. This is usually the user who created the file, although this can be changed.Users can also be classed into groups, so similar users can be grouped together. The other element is the access permissions for the file. These are split into three areas: • Who can read (view) the file ( r) • Who can write to the file (w) • Who can run the file (this only applies to files that can be run) (x) Let’s look an example. Open a console and do a directory listing by typing: ls -al at the command line.  This is simply a directory listing, but lets look at one line as an example: -rw-r r   1   jono    jono    1701    Jul 13 15:23   test.txt A lot of information is given. Reading the information from left to right, this is what it means: -           File type indicator (- means normal file) rw-r r File permissions jono   Owner jono  

Commands Related to Processes

To see currently running process  ps $ps List the process using most CPU Top , htop $top To stop any process by PID i.e. to kill process kill    {PID} $kill  1012 To stop processes by name i.e. to kill process killall   {Process-name} pkill xkill $killall httpd To get information about all running process ps -ag $ps -ag To stop all process except your shell kill 0 $kill 0 For background processing (With &, use to put particular command and program in background) linux-command  & $ls / -R | wc -l & To display the owner of the processes along with the processes    ps aux $ps aux To see if a particular process is running or not. For this purpose you have to use ps command in combination with the grep command ps ax | grep  process-U-want-to see For e.g. you want to see whether Apache web s

MySQL

MySQL MySQL is an open source database management software that help users store, organize, and  retrieve data. It is a very powerful DBMS with a lot of flexibility  quickinstallation of MySQL server sudo apt-get update sudo apt-get install mysql-server Once you have MySQL installed on your droplet, you can access the MySQL shell by typing the following command into terminal: mysql -u root -p All MySQL commands end with a semicolon; if the phrase does not end with a semicolon, the command will not execute.  You can quickly check what databases are available by typing: SHOW DATABASES; Creating a database is very easy: CREATE DATABASE database name; You would delete a MySQL database with this command: DROP DATABASE database name; Let’s open up the database we want to use:  USE databasename; you can also see an overview of the tables that the database contains. SHOW tables; Let’s create a new MySQL table: CREATE TABLE potluck (id INT NOT NULL PRIMARY KEY A

FTP

The File Transfer Protocol (FTP) is a standard network protocol used for the transfer of computer files from a server to a client using the Client–server model on a computer network. FTP is built on a client-server model architecture and uses separate control and data connections between the client and the server. FTP users may authenticate themselves with a clear-text sign-in protocol, normally in the form of a username and password, but can connect anonymously if the server is configured to allow it. For secure transmission that protects the username and password, and encrypts the content, FTP is often secured with SSL/TLS (FTPS). SSH File Transfer Protocol (SFTP) is sometimes also used instead; it is technologically different. The first FTP client applications were command-line programs developed before operating systems had graphical user interfaces, and are still shipped with most Windows, Unix, and Linux operating systems. ftp utility is used to connect,manage

wget utility

wget utility is the best option to download files from internet. wget can pretty much handle all complex download situations including large file downloads, recursive downloads, non-interactive downloads, multiple file downloads etc. 1. Download Single File with wget The following example downloads a single file from internet and stores in the current directory. $wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2 2. Download and Store With a Different File name Using wget -O $wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701 3. Continue the Incomplete Download Using wget -c Restart a download which got stopped in the middle using wget -c option as shown below. $wget -c http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2 4. Download in the Background Using wget -b For a huge download, put the download in background using wget option -b as shown below. $wget -b http://www.openss7.org/repos/tarballs/strx25-0.9

curl command

Transferring data from one place to another is one of the main task done using computers connected to a network. There are so many GUI tools out there to send and receive data, but when you are working on a console, only equipped with command line functionality, using curl is inevitable. A less known fact is that curl can work with a wide range of protocols and can solve most of your scripting tasks with ease. Haxx is a team of developer consultants offering solutions to programming problems. They offer solutions in the field of Embedded programming, Unix/Linux, Network, Device Drivers, Perl scripts etc. One of the co-founder of Haxx gifted the open-source community with a tool called CURL. The man behind its development is none other than Daniel Stenberg(who is currently a Senior Network Engineer @ Mozilla.) CURL comes by default installed in most of the distributions. If you do not have curl tool installed, then its a single apt-get(apt-get install curl) or yum(yum ins

command line arguments in bash script

To input arguments into a bash script, like any normal command line program, there are special variables set aside for this The arguments are stored in variables with a number in the order of the argument starting at 1 First Argument: $1 Second Argument: $2 Third Argument: $3 Example command: ./script.sh alpha beta gamma Variables: $1=='alpha'; $2=='beta'; $3=='gamma' The variable $0 is the script's name.   The total number of arguments is stored in $#.  The variables $@ and $* return all the a rguments. Script Example #!/bin/bash echo "the $1 eats a $2 every time there is a $3" echo "bye:-)" Command: ./script.sh dog bone moose Output: the dog eats a bone every time there is a moose  bye:-)

loops in bash shell- for , while and until

Loops allow us to take a series of commands and keep re-running them until a particular situation is reached. They are useful for automating repetitive tasks. There are 3 basic loop structures in Bash scripting which we'll look at below. There are also a few statements which we can use to control the loops operation. while loop One of the easiest loops to work with is while loops. They say, while an expression is true, keep executing these lines of code. They have the following format: while [ test condition ] do #statements done Example: print all odd numbers less than 50 i=1 while [ $i -le 50 ] do echo $i i=`expr $i + 2` done until loop The until loop is fairly similar to the while loop. The difference is that it will execute the commands within it until the test becomes true.  Syntax until [ test condition ] do #statements done Example: print all odd numbers less than 50 i=1 until [ $i -ge 50 ] do echo $i i=`expr $i + 2` done for loop The for loo

Different syntax for writing arithmetic expressions in bash shell

#!/bin/bash echo "Enter two numbers" read a b s=`expr $a + $b` echo "Sum1=$s" s=$[$a+$b] echo "sum2=$s" ((s=$a+$b)) echo "sum3=$s" ((s=a+b)) echo "sum3=$s" let s=$a+$b echo "sum4=$s" let s=a+b echo "sum4=$s" Note:bash shell support only integer arithmetic.zsh support operations on real numbers.We can use bc in bash shell to do real arithmetic. Eg: echo "$a*$b"|bc   # where a and b are real Mathematical Operators With Integers Operator Description Example Evaluates To + Addition echo $(( 20 + 5 )) 25 - Subtraction echo $(( 20 - 5 )) 15 / Division echo $(( 20 / 5 )) 4 * Multiplication echo $(( 20 * 5 )) 100  % Modulus echo $(( 20 % 3 )) 2 ++ post-increment (add variable value by 1) x=5 echo $(( x++ )) echo $(( x++ )) 5 6 -- post-decrement (subtract variable value by 1) x=5 echo $(( x-- )) 4 ** Exponentiation x=2 y=3 echo $(( x **

Menu driven program to do some shell commands

#menu driven program to do some shell functionality   while true   do       cat <<menu            1.date           2.cal           3.directory           4.exit      menu echo "Enter your choice" read op     case $op in     1) echo "todays date is"        date;;     2) echo "current month calendar"        cal;;     3)echo "directory listing"        ls;;     4)exit;;     *)echo "invalid option";;     esac done Note: Here the while true statement will make the loop to execute infinitely.The exit statement cause the program to terminate when the option 4 is pressed.cat command is used here for making a menu.You can also use simple echo statement. Another efficient way to create menu in bash shell script is to use select statement as shown below. menu="date cal dir exit" PS3="Enter choice..:" select op in $menu do     case $op in     'date') echo "todays date is"

GUI menus in bash shell script

#!/bin/bash #menu driven program to display memoryinfo and cpuinfo while true do dialog --menu "Choose one:" 10 30 3 1 MemoryInfo 2 CPUInfo 3 exit 2>op o=`cat op`    case $o in    1)cat /proc/meminfo>tmp       dialog --title "Memory Info" --textbox tmp 22 70;;      2)cat /proc/cpuinfo>tmp        dialog --title "CPU Info" --textbox tmp 22 70;;    3)clear        exit;;      esac done  #example 2 while true do  dialog --menu "Enter choice" 12 30 4 1 date 2 cal  3 ls 4 exit  2>op   o=`cat op`   case $o in   1)date >t     dialog --title "date" --textbox t 10 30;;   2) cal 01 2020 >t       dialog --title "calendar" --textbox t 15 40;;   3)ls >t       dialog --title "list of files" --textbox t 30 40;;   4)clear      exit;;   esac done

Gambas--GAMBAS Almost Means BASIC

Gambas is the name of an object-oriented dialect of the BASIC programming language, as well as the integrated development environment that accompanies it. Designed to run on Linux and other Unix-like computer operating systems, its name is a recursive acronym for Gambas Almost Means Basic.Gambas is also the word for prawns in the Spanish and Portuguese languages, from which the project's logos are derived. Gambas was developed by the French programmer Benoît Minisini, with its first release coming in 1999. Benoît had grown up with the BASIC language, and decided to make a free software development environment that could quickly and easily make programs with user interfaces. Ckeck whether Gambus is installed if not enter these commands one by one. sudo add-apt-repository ppa: shrimp-team / gambas3 sudo apt-get update sudo apt-get install gambas3 Know more about Gambas here http://gambas.sourceforge.net/en/main.html  http://gambaswiki.org/wiki/tutorial Developing ap