KwickAcademy Course Topics · 5 min · free
Automating tasks with scripts
Automate tasks with shell scripts: for and while loops, renaming many files, functions, keeping a log, and scheduling with cron. Automation means the computer repeats the work by itself; crontab -e schedules a script.
Follows the syllabus of: GSEB Std 11 Computer Studies
On screen in this lesson
What is automation?
| Automation: the computer does the task by itself |
| Saves time: one command replaces many |
| Avoids mistakes: same steps every time |
| Can run on a schedule, even when you are away |
Tools for automation
| Tool | Does | Keyword |
|---|---|---|
| for loop | repeat for a list | for ... do done |
| while loop | repeat while true | while ... do done |
| function | reuse commands | name() { } |
| cron | run at a time | crontab -e |
Common loop mistake
| Forget i=$((i + 1)) and i stays 1 |
| The condition never becomes false |
| Result: an infinite loop |
| Press Ctrl+C to stop it |
Scheduling with cron
| Field | Range | Star means |
|---|---|---|
| 1. minute | 0 to 59 | every minute |
| 2. hour | 0 to 23 | every hour |
| 3-4. day, month | 1-31, 1-12 | every day |
| 5. weekday | 0-7, 0 and 7 Sun | every day |
Pause and predict
| 0 18 * * 1 /home/riya/report.sh |
| Minute 0, hour 18: 6:00 in the evening |
| Weekday 1: Monday |
| Answer: every Monday at 6 PM |
Quick recap
| Automation: the computer repeats work by itself |
| for: repeat for each item in a list |
| while: repeat while true; update the variable |
| Functions reuse steps; >> adds to a log file |
| crontab -e schedules scripts: min hour day month weekday |
Quick answers
What does 0 18 * * 1 mean in cron?
Every Monday at 6 PM.
Forget i=$((i + 1)) in a while loop. What happens?
An infinite loop; press Ctrl+C.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
The full lesson, in text
Hello students, welcome to Kwickprep. Imagine copying fifty files and renaming each one by hand. It is slow, boring, and easy to get wrong. Today we will learn how scripts repeat such work for us, and even run on their own at a fixed time.
First, a new term. Automation means making the computer do a task by itself, without a person doing each step. It saves time, because one command replaces many. It avoids mistakes, because the script does the same steps the same way every time. And with scheduling, the task can even run while you are away.
Scripts automate work with a few building blocks. A for loop repeats steps for each item in a list. A while loop repeats steps as long as a condition is true. A function gives a name to a group of commands, so we can reuse them. And cron runs a script automatically at a fixed time.
Here is a for loop. The variable day takes each value in the list, one at a time. Do starts the block to repeat, and done ends it. The list has three days, so the echo runs three times. Pause and predict. How many lines print if we add Thu to the list? Four lines.
Now real automation. The star dot txt matches every text file in the folder. For each file, mv renames it by adding old, dash, in front. If the folder has fifty text files, this one loop renames all fifty in a second. Test such loops on a copy of your files first.
A while loop repeats as long as its condition is true. Here i starts at one. The test asks, is i less than or equal to three? Each round prints the round number, and then adds one to i. When i becomes four, the test is false and the loop stops.
One mistake appears in many answer sheets. If you forget the line that adds one to i, the variable i stays one forever. The condition never becomes false, so the loop never stops. This is called an infinite loop. Press Ctrl+C in the terminal to stop it.
A function gives a name to a group of commands. Here the function is called greet, and it prints Good morning with a name. Dollar one means the first value passed to the function. We call greet twice, with Riya and then Aman, without writing the echo again.
An automatic script runs when nobody is watching, so it should write a log. A log is a file that records what happened and when. The double greater than sign adds a line to the end of the file. A single greater than sign would wipe the old lines, so use two.
Cron is a Linux service that runs commands at fixed times. Each cron line starts with five time fields. The first two are the minute and the hour, in twenty four hour time. The next two are the day of the month and the month. The fifth is the day of the week, where zero and seven both mean Sunday. A star in any field means every value of that field.
To add a job, type crontab -e, which opens your cron table in an editor. This line has minute thirty and hour nine. The other three fields are stars, so it runs every day at nine thirty in the morning. It runs the script backup.sh from the home folder of the user riya.
Pause and predict. What does the line zero, eighteen, star, star, one mean? Minute is zero and hour is eighteen, which is six in the evening. The weekday field is one, which means Monday. So the script runs every Monday at 6 PM.
Let us revise what we learned today. Automation lets the computer repeat work by itself, quickly and without mistakes. A for loop repeats steps for every item in a list. A while loop repeats while a condition is true, so always change the variable. Functions reuse commands, and double greater than adds lines to a log. Crontab -e schedules a script with five time fields.
Courses that teach this
| Course | Unit |
|---|---|
| GSEB Std 11 Computer Studies | Advanced Scripting |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.


