Day 5: Advance Linux Shell Scripting
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.
#!/bin/bash
prefix=$1
start=$2
end=$3
for (( i=$start; i<=$end; i++ ))
do
mkdir "${prefix}${i}"
done
~
Example 1: When the script is executed as
./
createDirectories.sh
day 1 90
then it creates 90 directories as day1 day2 day3 .... day90
Based on the information provided, it seems that the script “createDirectories.sh” takes three arguments when executed: “day”, “1”, and “90”.
The script likely uses a loop to create 90 directories with names in the format “dayX”, where X ranges from 1 to 90. The loop can be constructed using the shell’s for loop construct and a counter variable that increments on each iteration. Here’s an example implementation of the script in Bash:
Output :-
Create a Script to back up all your work done till now.
Read About Cron and Crontab, to automate the backup Script
Cron is an effective and popular command-line utility used to schedule tasks at a specified time and day without user interaction.
The scheduled tasks are known as cron jobs while the crontab is the list of the file containing the cron jobs.
Crontab is useful to perform various operations such as handling automated backups, rotating log files, syncing files between remote machines and clearing out temporary folders, etc.
The crond daemon is the background service that enables cron functionality.
crontab -e
: Edit crontab file, or create one if it doesn’t already exist.crontab -l
: Display crontab file contents.crontab -r
: Remove your current crontab file.crontab -i
: Remove your current crontab file with a prompt before removal.crontab -u <username>
: Edit other user crontab files. This option needs system administrator privileges.
Read about User Management
User management in Linux is the process of creating, modifying, and deleting user accounts on a Linux system. In Linux, each user has a unique username and password, which are used to log in and access the system.
adduser
: Add a user to the system.passwd
: Set password fro useruserdel
: Delete a user account and related files.addgroup
: Add a group to the system.delgroup
: Remove a group from the system.usermod
: Modify a user account.sudo
: Run one or more commands as superuser permissions.