Hello, everyone, this is my 5 blog. From this blog, I want to share my 5th-day experience OR some information on Advanced Linux Shell Scripting for DevOps Engineers with User Management.
Advanced Linux Shell Scripting for DevOps Engineers with User Management #shubhamlondhne
INTRODUCTION TO BASIC LINUX.
Lists of contents.
- You have to do the same using Shell Script i.e using either Loops or command with start day and end day variables using arguments -
So Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is directory name and second is start number of directories and third is the end number of directories ) it creates specified number of directories with a dynamic directory name.
Example 1: When the script is executed as
./
createDirectories.sh
day 1 90
then it creates 90 directories as day1 day2 day3 .... day90
Example 2: When the script is executed as
./
createDirectories.sh
Movie 20 50
then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50
Notes: You may need to use loops or commands (or both), based on your preference . Check out this reference: https://www.geeksforgeeks.org/bash-scripting-for-loop/
- Create a Script to back up all your work done till now.
Backups are an important part of DevOps Engineers day to Day activities The video in References will help you to understand How a DevOps Engineer takes backups (it can feel a bit difficult but keep trying, Nothing is impossible.) Watch this video
In case of Doubts, post it in Discord Channel for #90DaysOfDevOps
- Read About Cron and Crontab, to automate the backup Script
Cron is the system's main scheduler for running jobs or tasks unattended. A command called crontab allows the user to submit, edit or delete entries to cron. A crontab file is a user file that holds the scheduling information.
Watch This video as a Reference to Task 2 and 3 https://youtu.be/aolKiws4Joc
- Read about User Management and Let me know on Linkedin if you're ready for Day 6.
A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system. In this post, we will learn about users and commands which are used to get information about the users. After installation of the operating system, the ID 0 is assigned to the root user and the IDs 1 to 999 (both inclusive) are assigned to the system users and hence the ids for local user begins from 1000 onwards.
- Create 2 users and just display their Usernames
Check out this reference: https://www.geeksforgeeks.org/user-management-in-linux/
Post your daily work on Linkedin and le me know , writing an article is the best :
LETS START WITH SOME INTERESTING INFORMATION
- You have to do the same using Shell Script i.e using either Loops or command with start day and end day variables using arguments -
So Write a bash script create Directories.sh that when the script is executed with three given arguments (one is directory name and second is start number of directories and third is the end number of directories ) it creates specified number of directories with a dynamic directory name.
Example 1: When the script is executed as
./createDirectories.sh day 1 90
then it creates 90 directories as day1 day2 day3 .... day90
Example 2: When the script is executed as
./
createDirectories.sh
Movie 20 50
then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50
Notes: You may need to use loops or commands (or both), based on your preference . Check out this reference: https://www.geeksforgeeks.org/bash-scripting-for-loop/
ANS:-
It ascertains whether the script is invoked with precisely three parameters.
From the input arguments, it retrieves the start number, end number, and directory name.
It determines whether the start and finish numbers are the same or less.
By attaching the numbers to the directory name, it creates directories from the start number to the finish number using a for loop.
The directories are created using the mkdir -p command, and a message is printed for each directory that is created.
Ultimately, a notice stating that the directories were successfully established is displayed.
You can save this script in a file named createDirectories.sh, make it executable with chmod +x createDirectories.sh, and then run it as shown in your examples:
Explames 1 :- ./createDirectories.sh day 1 90
Explames 2 :- ./createDirectories.sh Movie 20 5
- Create a Script to back up all your work done till now.
Backups are an important part of DevOps Engineers day to Day activities The video in References will help you to understand How a DevOps Engineer takes backups (it can feel a bit difficult but keep trying, Nothing is impossible.) Watch this video
ANS:-
It's a good idea to write a backup script to protect your data and work. Here is a basic Bash script example that you may use to make a backup of your work. The files and folders you specify will be compressed and stored in a backup folder by this script.
Establish a directory, like ~/backups, for the storage of backups. This can be changed to a different address.
If the backup directory isn't there already, make it.
Using the current date and time, create a timestamp to identify each backup individually.
In the backup_list array, enumerate the files and folders that you wish to backup.
The backup_list's elements are iterated over.
Verify that every item is present.
If the item is present, make a compressed archive in the backup directory using the timestamp as the filename (in this example, a.tar.gz file).
Print a message stating that the object was not discovered if it doesn't exist.
Once all the designated items have been backed up, print a message to confirm that the backup procedure has been completed.
The files and folders you wish to back up can be added to the backup_list array according to your preferences. To build a backup, save this script to a file (backup_script.sh, for example), make it executable (chmod +x backup_script.sh), and run it.
- Read About Cron and Crontab, to automate the backup Script
Cron is the system's main scheduler for running jobs or tasks unattended. A command called crontab allows the user to submit, edit or delete entries to cron. A crontab file is a user file that holds the scheduling information.
ANS:-
In operating systems that resemble Unix, Cron and Crontab are crucial tools for automating processes and setting up jobs to execute at specific times. The main scheduler on the system is called Cron, and the command Crontab is used to control the cron schedule.
- Cron
In operating systems resembling Unix, Cron is a time-based work scheduling tool. It can carry out scripts or tasks at predetermined periods or on a regular basis (daily, weekly, or monthly), all while operating in the background. Cron plays a crucial role in automation and system management activities.
- Important aspects of Cron:
Time-Based Scheduling: You can set up tasks with Cron to execute on particular days, hours, or intervals.
System-Wide Scheduler: Cron can do tasks as any user on the system and is accessible throughout the system.
Background Service: It operates in the background, continuously looking for tasks that are scheduled to be completed.
Cron maintains task execution logs, which are useful for troubleshooting.
- A Crontab
Users can create, edit, and manage their scheduled tasks in a "cron table" by using the Crontab command, which is short for "cron table." On a Unix system, each user may have a unique crontab. For that particular user, a list of jobs and schedules is contained in the crontab file.
- Important aspects of Crontab:
User-Specific Scheduling: With their own crontab, each user is able to arrange tasks to suit their own schedule.
Simple Editing: Compared to directly editing system cron files, Crontab offers a more user-friendly method for editing the schedule.
command Execution: With Crontab, users can plan when to run scripts, programs, or commands.
Syntax: Fields that define the day of the week, month, minute, and hour that a task should execute are included in crontab entries. On the basis of this syntax, users can alter their schedules.
- Here's an illustration of how to automate the backup script using Crontab:
Use the crontab -e command to view and edit the user's crontab.
To schedule your backup script, add an entry. For instance, you could add the following line to have your backup script run every day at two in the morning:
0 2 /path/to/backup_script.sh*
The 0 in the first field represents the minute (0-59).
The 2 in the second field represents the hour (0-23).
The asterisks in the remaining fields (* *) represent any day of the month, any month, and any day of the week.
After saving, close the crontab editor.
Now, at the appointed time, the designated backup script will execute automatically.
In conclusion, on Unix-like systems, Cron and Crontab are effective tools for job scheduling and task automation. Cron is in charge of carrying out the tasks in accordance with the schedule, and Crontab offers an easy way to specify when and how they should run. Using Cron and Crontab to automate backups and other repetitive tasks can help organize system administration and guarantee that important tasks are completed on schedule.
- Read about User Management and Let me know on Linkedin if you're ready for Day 6.
A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system. In this post, we will learn about users and commands which are used to get information about the users. After installation of the operating system, the ID 0 is assigned to the root user and the IDs 1 to 999 (both inclusive) are assigned to the system users and hence the ids for local user begins from 1000 onwards.
ANS:-
User management is a critical aspect of system administration in a Linux operating system. It involves creating, modifying, and managing user accounts, as well as controlling user access and privileges. Here are some key aspects of user management in Linux:
1. User Accounts: A user account is an entity that allows an individual to interact with a Linux system. Each user is identified by a username, and they are assigned a unique user ID (UID) and a primary group ID (GID). The root user, with UID 0, has superuser privileges and is often used for system administration tasks.
User Information: User accounts store various information, including the username, user ID, home directory, default shell, and more. This information is usually stored in the /etc/password file.
User Groups: Users can belong to one or more groups, which are used to manage permissions and access control. Group information is stored in the /etc/group file.
Adding Users: The useradd command is used to add new users to the system. You can specify various user attributes, such as the home directory, default shell, and more, while adding a user.
Modifying Users: The usermod command allows you to modify user account settings, such as changing the user's home directory, shell, or GID. You can also use it to unlock or lock user accounts.
. Deleting Users: The userdel command is used to delete user accounts. Be cautious when deleting users, as this action can result in the loss of user data.
Password Management: The passwd command is used to change a user's password. It can be executed by the user to change their own password or by the system administrator to manage other users' passwords.
User Permissions: File and directory permissions can be set to control access to data. Users can be granted read, write, and execute permissions based on file ownership and group membership.
User Management Files: User account information is typically stored in /etc/passwd. Password information (hashed and salted passwords) is stored in /etc/shadow. Group information is stored in /etc/group.
Rights of Users: The root user, also known as the superuser, can carry out administrative operations and has complete control over the system. Regular users can need elevated privileges (like using sudo) to perform administrative tasks because they have limited privileges.
- Create 2 users and just display their Usernames
Check out this reference: https://www.geeksforgeeks.org/user-management-in-linux/
Post your daily work on Linkedin and le me know , writing an article is the best :
ANS:-
- To create two users and display their usernames, you can use the following steps in a Linux terminal. Here's how you can do it:
1. Open a terminal window.
2. Use the useradd command to create the first user. Replace "user1" with the username you want to create:
- bash
sudo useradd user1
- Use the useradd command to create the second user. Replace "user2" with the username you want to create:
- bash
sudo useradd user2
- To display the usernames of the two users you've just created, you can use the awk command in combination with the /etc/passwd file:
- bash
cat /etc/passwd | awk -F: '{ print $1 }'
- This command will display a list of usernames, including the two new users you created.
Regarding your suggestion about sharing daily work on LinkedIn, writing articles can be a great way to share your knowledge and experiences. LinkedIn is a professional networking platform, and creating and sharing articles can help you showcase your expertise and engage with your professional network. When writing articles, consider these tips:
Choose Relevant Topics: Write about topics that are relevant to your industry or area of expertise. Sharing valuable insights and knowledge can help you establish yourself as an authority in your field.
Provide Value: Offer practical advice, solutions to common problems, or insights into industry trends. Aim to provide value to your readers.
Engage Your Audience: Encourage discussions and interactions by asking questions or inviting comments on your articles. Respond to comments and engage with your connections.
Be Consistent: If you plan to share daily work or insights regularly, maintain a consistent posting schedule. Whether it's daily, weekly, or monthly, consistency can help you build a following.
Use Visuals: Incorporate images, infographics, or relevant media to make your articles more engaging and visually appealing.
Proofread: Ensure your articles are well-written and free from grammatical errors. Proofreading is essential for maintaining a professional image.
Promote Your Work: Share your articles on your LinkedIn feed and other social media platforms to reach a broader audience.