Advanced Linux Shell Scripting for DevOps Engineers with User Management
- Write a bash script create directories.sh that when the script is executed with three given arguments (one is the directory name and the second is the start number of directories and the third is the end number of directories ) it creates a specified number of directories with a dynamic directory name.
Script :
#!/bin/bash
name=$1
start_name=$2
end_name=$3
for (( i=start_name; i<=end_name; i++))
do mkdir "$name$i"
done
- Create a Script to back up all your work done till now.
Script:
#!/bin/bash
src_dir=/home/ubuntu/my_scripts
tgt_dir=/home/ubuntu/yash
curr_timestamp=$(date "+%Y-%m-%d-%H-%M-%S") backup_file=$tgt_dir/$curr_timestamp.tgz
echo "Taking backup on $curr_timestamp"
tar -cvzf $backup_file --absolute-names $src_dir
echo "Backup complete"
Cron and Crontab :
Cron- Cron is the general name for the service that runs scheduled actions. crond is the name of the daemon that runs in the background and reads crontab files.
Crontab- Crontab is a command that is found in the Linux Operating system to Schedule tasks. Crontab stands for “cron table, ” because it uses the job scheduler cron to execute tasks.
User Management:
In Linux, user management involves creating, modifying, and deleting user accounts and groups. Here are some commonly used commands for user management in Linux:
useradd: The "useradd" command is used to create a new user account.
passwd: The "passwd" command is used to set or change a user's password.
Here are some common options for the "passwd" command:
"-l": Lock the user's account.
"-u": Unlock the user's account.
"-d": Remove the user's password.
Thank you all for giving your valuable time for reading.