Day 5 - Advanced Linux Shell Scripting

Day 5 - Advanced Linux Shell Scripting

Yes!! We have completed the " How to write shell scripts using basic command of Linux in Day 4".😎

So, Now moving ahead with some advance shell scripts.

Multiple Directories using Shell Script

CRON Jobs

Cronjob or Scheduled jobs is meant for performing regular scheduled actions such as backups, report generation, and so on.

Creating cron jobs helps reduce human error and save time as you don’t need to repeatedly perform the same tasks.

How Cron Jobs Work

Cron is a daemon – a background process executing non-interactive jobs. In Windows, it works similarly to background processes like Services.

A cron file is a text file that contains commands to run periodically at a specific time. The cron table or crontab configuration file is /etc/crontab by default.

Crontab Syntax

The syntax for crontab command

When preparing for cron jobs, you must understand cron’s syntax and formatting to ensure the script runs properly. The crontab syntax consists of five fields with the following possible values:

  • Minute. The minute of the hour the command will run, ranging from 0-59.

  • Hour. The hour the command will run, ranging from 0-23 in a 24-hour notation.

  • Day of the month. The date of the month the user wants the command to run, ranging from 1-31.

  • Month. The month that the user wants the command to run. It ranges from 1-12, representing January until December.

  • Day of the week. The day of the week for a command to run, ranging from 0-6. The value represents Sunday-Saturday. In some systems, the value 7 represents Sunday.

If you don’t have a specific value, avoid leaving these fields blank and enter an asterisk instead.

User Management

In a Linux system, users refer to individuals or entities that interact with the operating system by logging in and performing various tasks. User management plays a crucial role in ensuring secure access control, resource allocation, and system administration.

A user in Linux is associated with a user account, which consists of several properties defining their identity and privileges within the system. These properties are a username, UID (User ID), GID (Group ID), home directory, default shell, and password.

Each user account possesses these unique properties listed above.

Below are some useful commands for creating user or adding it to a group and so on:-

sudo useradd username -> To create user 
sudo useradd -m username -> To create user in home location
Note : Whenever we create user, the user is added to the group of same username by default.
cat /etc/passwd -> To check user account properties
sudo passwd username -> For creating user account password
su username -> For switching user account
sudo groupadd groupname -> For adding groups
cat /etc/group -> For checking list of groups
sudo usermod -aG groupname username -> For adding user to a group
sudo gpasswd -d username groupname -> To delete a user from group
sudo userdel username -> For deleting user
sudo groupdel groupname -> For deleting group

Conclusion

In Conclusion, We have learn how to make multiple directories using Shell script, about Cron Jobs and about User Management.

A cron job is a task automated using cron, a scheduler tool on a Unix-like operating system. Common cron jobs include creating a backup, updating software, clearing the cache, and monitoring the server.

Have understood the various aspects of user management, which includes creating, modifying, and deleting user accounts, implementing user authentication.

👆The information presented above is based on my interpretation. Suggestions are always welcome.😊

~ Smriti Sharma✌