Day 5 : Advanced Shell Scripting
- Write a bash script createDirectories.sh. When the script is executed with three given arguments (directory name, start number and end number) it creates a specified number of directories with a dynamic directory name.
Lets first create a shell script file called as CreateDirectories.sh > command in terminal will be nano CreateDirectories.sh
2.Create a Script to back up all your work done till now.
Now lets create a file name backup.sh and write a shell script
Now the script start with shebang . Will create a suffix variable called as suffix and whichh will append the folder with the system date and time. Now we will create another variable called as backup_directory where we will ask to backup and then copy all the folders which are there is the current pwd .
Now lets try to run the command
Now we can see the output where all the dirctories had been backed up respectively.
3. Read About Cron and Crontab, to automate the backup Script
Cron is an essential part of any system, as it automates various scheduled tasks. The crontab command is used to edit and manage cron jobs. Creating a cron job is not difficult, but it can become tricky when dealing with multiple users and environments. Crontab syntax is mostly the same across all Linux distributions and servers, so once you get the hang of it you’ll be scheduling tasks in no time!
4. Read about User Management
User is an entity that can manipulate files and perform serveral other operations. Each user in a Linux operating system is assigned an id. After installation of the OS, ID 0 is assigned to the root user. ID 1–999 are assigned to system users and ID from 1000 onwards are assigned to local user.
1. Command to get id of a user
id username
2.Command to add a user
3.Command to assign password to a user
passwd username
4.Command to access user configuration
5.Command to delete a user
userdel -r username
6.For switching user account
su username
5. Create 2 users and just display their Username