├── Cron Job-Shell-Commands-part6 ├── README.md ├── Shell-Commands-part1 ├── Shell-Commands-part2 ├── Shell-Commands-part3 ├── Shell-Commands-part4 ├── Shell-Commands-part5 └── resume-devops.docx /Cron Job-Shell-Commands-part6: -------------------------------------------------------------------------------- 1 | The crontab is a list of commands that you want to run on a regular schedule,. 2 | 3 | Linux Crontab Format 4 | MIN HOUR DOM MON DOW CMD 5 | 6 | For eg : 30 08 10 06 * ls -latr /home/ ==>30 – 30th Minute 08 – 08 AM 10 – 10th Day 06 – 6th Month (June) * – Every day of the week . 7 | 8 | crontab -l ==> To view the crontab entries as the user root . 9 | crontab -u user-name -l ===>> View the Crontab entry for other user . 10 | 11 | To edit crontab entry : crontab -e 12 | * * * * * ls -latr /home/ ==> The * means all the possible unit — i.e every minute of every hour through out the year. 13 | 14 | This example checks the status of docker service(including weekends) during the working hours 9 a.m – 6 p.m 15 | 00 09-18 * * * /usr/local/bin/script-to-check-if-docker-running. 16 | OR 17 | crontab -l 18 | * * * * * /root/hello.sh > ~/cron-test.txt 19 | 20 | script-to-check-if-docker-running.sh 21 | #!/bin/bash 22 | service="docker" 23 | /bin/systemctl -q is-active "$service.service" 24 | status=$? 25 | if [ "$status" == 0 ]; then 26 | echo "OK" 27 | else 28 | echo "Not ok" 29 | fi 30 | 31 | chmod 777 script-to-check-if-docker-running.sh 32 | 33 | To verify if cronjob is running : 34 | grep "script-to-check-if-docker-running.sh" /var/log/cron 35 | OR, 36 | cat ~/cron-test.txt 37 | 38 | Cron special keywords and its meaning 39 | 40 | Keyword Equivalent 41 | @yearly 0 0 1 1 * 42 | @daily 0 0 * * * 43 | @hourly 0 * * * * 44 | @reboot Run at startup. 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Linux-projects Test 2 | -------------------------------------------------------------------------------- /Shell-Commands-part1: -------------------------------------------------------------------------------- 1 | Terminal: Its a kind of app that handles the input from user and displays the output . For example : In Mac os we have iTerm2 or in windows its putty. 2 | Shell : Its a command line interface. It provides an interface between the user and the kernel and executes programs called commands. 3 | The Shell is the name of the program that runs in the terminal 4 | Types of Shell : Bash Shell , ZSH shell . 5 | How to check which shell are we using : echo $SHELL. 6 | echo is like print statement , it will show the value for the arguments passed here as a input like $SHELL(means get the value of SHELL command) 7 | Once we open Terminal it will have option like this : 8 | [root@ins-dm-gjtestmysql101z ~]# ==> So basically here root is the user on server , @ is seprator and ins-dm-gjtestmysql101z is the hostname of machine . 9 | Hostname is basically the name of server by which it will be called in the network . It can be viewed using the command : hostname. 10 | Scenario: Lets say if am running python3 command , how does system will understand if its executable or its a file . Basically behind the scene it run 11 | the commmand "where python3 " and it will be execute then ==> where python3 (o/p =Note − /usr/local/bin/python3 is the path of the Python directory.) 12 | ls : list of files in present working directory 13 | ls -a : Show all the hidden files in the directory 14 | pwd: present working directory 15 | Once i open a new directory it will by default point to my home directory i.e /Users/kriti 16 | Whatever command i will run , it will execute in the same folder where currently i will be pointing to 17 | mkdir test : Create a new folder with test name 18 | cd test: Change current working directory/folder to test folder 19 | cd.. : To get one folder back from current working directory 20 | Environment variable in linux : Environment variables allow to customize how the system works and the behavior of the applications on the system. 21 | echo $PATH : It specifies the directories to be searched to find a command . like if we run python3 command it is going to search that executable command 22 | in each of the location specfied in PATH Env variable. 23 | cat ~/.bashrc. ==> Cat displays the content of a file . So basically here it means to open display the content of bashrc file located in home directory 24 | bashrc is a file that will automatically be loaded once a interactive terminal open . So all kind of env variable settings or alias setting we store here 25 | alias : Alias in shell means to set short names for a long command like [alias a="docker run nginx"] . Now if we run "a" then it will call "docker run nginx" 26 | Now to set environment variable in shell we need to use export command like [export mysql_password="my-secret-pw"]. This will only be valid for a particular 27 | terminal session . If you need change permanent then make change in bashrc file as explained above . 28 | echo $mysql_password ==> Will give value of mysql_password variable. 29 | cat > file.txt. ==>Creating and writing to the same file 30 | My name is kriti and to do exit press (ctrl+c) 31 | Now see content of file.txt , it will show the content as "My name is kriti" 32 | 33 | 34 | Assignments: 35 | 1. get hostname of your machine 36 | 2. Export two variables named as MY_SQL_USER and MY_SQL_PASSWORD 37 | 3. Echo the two variable values 38 | 4. Export the above two variables in bashrc file. 39 | 5. List all hiddden files in your home directory. 40 | 6. Create a directory in your home folder named as test and inside the test folder create file my_intro with content as your name. 41 | -------------------------------------------------------------------------------- /Shell-Commands-part2: -------------------------------------------------------------------------------- 1 | echo "Hello World" > devops.txt //Output of echo "Hello World" will be stored in devops.txt file . 2 | man echo //man command is used to get information of a particular command . Here i am trying to know more about echo command. 3 | cat devops.txt | tr a-z A-Z > DEVOPS.txt //Here it says that for the content of devops.txt , translate each character to upper case and then store it in DEVOPS.txt 4 | > Redirect symbol (Redirecting the output to another file) 5 | | pipe symbol(output of first command will act as input for second command 6 | touch devops.txt //touch is used to create new file 7 | cp devops.txt devops1.txt //make copy of devops.txt as devops1.txt 8 | mv devops.txt. devops1.txt //rename/move devops.txt as devops1.txt 9 | cp -R /test /test1 //copies the entire directory /test to /test1 10 | rm devops.txt //delete a file 11 | rm -R /test //delete the directory test 12 | rm -rf /test //If file/directory is opened then we can use -f option to forcefully delete it . 13 | sudo //Some commands need to be run as a superuser/admin user permission.It will ask for system password 14 | df -h //disk space and volume space (man df command) . -h is human readable format 15 | ls -latr | head -n 10 //here Head command will show first 10 lines of ls command output 16 | ls -latr | tail -n 10 //here tail command will show last 10 lines of ls command output 17 | head and tail we can use in with file also . Like head -n 2 devops.txt 18 | diff devops.txt devops1.txt //To list difference between two files . It will show the content that is not there in both files 19 | locate "*.txt" //It will show all the files in the current work directory which wil have extension as .txt . 20 | find . -type f -name "devops.txt" //find command to find a file or dir in the current directory .here i have defined the type as file and finding the file devops.txt in current directory 21 | * is wildcard . 22 | 23 | Note : For detail on any command use man and try different arguments with it . 24 | 25 | Assignments : 26 | 1. Create a file demo.txt using touch command and write around 20 lines in this file. 27 | 2. Print the output of first 5 lines from demo.txt and then last 5 lines . 28 | 3. find all the files inside your home directory whose last modification date is minimumm 20 minutes .Note:use man command to see arguments 29 | 4. create a file server.txt in /home and then move server.txt with name as server1.txt to /home/random directory . Note you need to create random directory here. 30 | 5. Delete the file server1.txt and the directory /home/random 31 | -------------------------------------------------------------------------------- /Shell-Commands-part3: -------------------------------------------------------------------------------- 1 | Here i am creating a user as devops and a group as devops.Also deleting them . 2 | 3 | adduser devops : add a user to the system. 4 | usermod devops --password devops : modify a user account. 5 | usermod -a -G Group-name user-name --> Add user to grup 6 | groupadd devops : add a group to the system. 7 | userdel devops : delete a user account and related files. 8 | groupdel devops : remove a group from the system 9 | 10 | chage devops : change user password expiry information. 11 | 12 | Relevant files which will change when user/group is created/modified. 13 | cat /etc/passwd 14 | cat /etc/shadow 15 | cat /etc/group 16 | 17 | 18 | Assignment : 19 | 1. Create a group named as demo . 20 | 2. create a user with your name in the group demo . 21 | 3. Using chage command change the password for your user. 22 | 4. Create a user with directory assigned as /var/lib. 23 | 5. View the content in /etc/passwd and /etc/group 24 | -------------------------------------------------------------------------------- /Shell-Commands-part4: -------------------------------------------------------------------------------- 1 | hostname : It gives the name assigned to the system in the network .Also It shows the system domain name. 2 | ifconfig : It is used to see current network settings on the system like its IP address . 3 | ping : Ping sends a packet of data to IP address or domain name , and see if packet is able to reach destination . Thus check if server is reachable or not. 4 | Like : ping www.google.com 5 | grep : It is used to display result based on a string filter . It is used to display the output based on regular expresssion . 6 | Like : ls -latr | grep devops 7 | ps -ef:list of user-initiated processes currently running in the current session. 8 | kill : If we want to kill any process manually then use kill command . 9 | Like :kill -9 /bin/python3 10 | service: A service is a process or group of processes (commonly known as daemons) running continuously in the background, waiting for requests to come in (especially from clients). 11 | systemctl : Systemctl is a command that we use to monitor,list, start and stop services . 12 | Like : Systemctl start service-name 13 | sytemctl stop service-name 14 | awk : It is used to manipulate data and generate reports . 15 | awk '{print $1,$4}' devops.txt ====> It will print the value of first and fourth column from devops.txt 16 | sed : sed is called as stream editor and it can perform lots of functions on file like searching, find and replace, insertion or deletion. 17 | sed 's/unix/linux/' devops.txt ====> Replacing unix with linux in devops.txt 18 | df -h == It is called as disk file system and it's used to get a full summary of available and used disk space usage of the file system on the Linux system. 19 | 20 | 21 | Assignments : 22 | 1. Install docker on centos machine .(Follow the doc https://docs.docker.com/engine/install/centos/) 23 | 2. Enable ,start and stop the docker service using systemctl command. 24 | 3. Store hostname, ip machine and disk usage of your system in a file called as system-conf.txt 25 | 4. In system-conf.txt replace ip machine with hostname of your machine. 26 | 5. Ping myntra website and check if server is reachable or not. 27 | 6. Kill the process running for your docker using kill command . 28 | -------------------------------------------------------------------------------- /Shell-Commands-part5: -------------------------------------------------------------------------------- 1 | File permissions in Linux:Each file or directory in linux is assigned with three types of owner i.e User,Group and others. 2 | Linux file ownership: 3 | USer -- User is owner of file ,By default who created the file is the onwer of file 4 | group: Group is defined as collection of users having the same permission . If you have a group of users from development team and want them to give same set 5 | of permissions for a file , then you can define permissions at group level and all the users inside that group will have same access. 6 | others: Other means access to the rest of world who is neither the owner or belong to any group. 7 | 8 | Linux file permissions: 9 | read : Permission to open and read a file . 10 | write : Permission to modify the content of file. 11 | execute : Execute permission means to run that command such as running .exe file for windows or .py for python code . 12 | 13 | To view the permission of file/dir assigned to the user,group or others run the command : ls -l 14 | Lets say you get output as -rw-r--r-- SA-sample.yaml. 15 | below is the detail of each character in -rw-r--r-- 16 | - ===>It shows that the output is of file type .If its d then directory type. 17 | rw- ==> The first three character belongs to user means user has read and write access to the file . Execute is - means no execute permission on file. 18 | r-- ===> The next three character belongs to the group .Means the user assigned to the group will have only read access to the file . 19 | r-- ==> The next three character belongs to others .Means all the other people will have only read access to the file . 20 | 21 | 22 | Number PermissionType Symbol 23 | 0 No Permission — 24 | 1 Execute –x 25 | 2 Write -w- 26 | 3 Execute+Write -wx 27 | 4 Read r– 28 | 5 Read+Execute r-x 29 | 6 Read+Write rw- 30 | 7 read+Write+Execute rwx 31 | 32 | chmod command: 33 | Lets say you have a file devops.txt and you want to give below permissions :This can either be done in numeric or symbolic way 34 | Read,write,execute to User 35 | read and write to group 36 | no permission to other 37 | This can be acheived using the command (chmod 760 devops.txt) ==>this in numeric way 38 | 39 | 40 | Now lets talk about how to change owner and group in linux: 41 | chown user filename ==> Now the filename will be owned by user (lets say kriti) 42 | chown user:group filename ==>changing both the user and group of file 43 | chgrp group_name filename ==>If you want to just change the group name for file 44 | 45 | su ---> To switch user: su kriti(switch user to kriti) 46 | Assignments: 47 | 1. Create three users A,B and C. 48 | 2. Create a group D , assign B and C user to that group. 49 | 3. Create a file devops.txt with user A. 50 | 4. Give Read,write and execute permission to Group D for devops.txt.Check if User B can modify the content of file and save it . 51 | 5. Change the owner of devops.txt to User C. 52 | -------------------------------------------------------------------------------- /resume-devops.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devops-Techstack/Linux-projects/608f3ce74ee816ff690b053661132c59eea41d83/resume-devops.docx --------------------------------------------------------------------------------