Basic task clip's This is our second script that we will create together and this will actually execute
some basic tasks that are like based on some basic commands.
So the task that we will define in our script is the first one is PWT that will present my working directory
LS which will list all the files or directories in my current directory.
Who am I.
It will print my username log and with the date the current date Kehl the current cat calendar and the
last one I want to create it three files in my directory that I'm logged in that files are A B C and
the command we would use to create them is touch.
So it's just that simple and that script will run sequentially if you remember it will do the first
one is PWT then LS And then so on.
So my machine is right here and I am going to create my second script.
Make sure I am logged in as myself and Biche directory on.
I'm in scripts directory perfect that's the directory I want it to be.
So I will go ahead and Vi a new file and the name of the file.
As basic tasks
it's just that simple.
Hit enter define your shell.
There keep making you do that again and again so you will remember date created the 0 8 20 20
description
run basic linux tasks date.
What was this 12:56 tell me.
Modified Yes.
Again you're not modifying you just putting today's date.
And I guess that's pretty much it now.
I always like to start my script with Echo so it will be a new line and this time I wanted to write
an echo this script will run a few basic tasks.
Now remember this is not a description.
This will actually output on the screen.
Then another Atco just for newline.
Now what do we want do we want to see which Deric to are or so simply just type p w d.
Ok it did that.
Now let's see if it could do.
LS Who am my date.
Cal and the last one is.
I wanted to create three files a b and c..
So that's pretty much it.
It's going to run one two three four five six commands six basic tasks require those tasks.
What exactly they're going to do.
And go ahead and escape out of it and right quit.
Save the pile and check the permissions.
There are no permissions assigned the permissions basic tasks unless mind set to your just to confirm
the basic tasks script has been created.
Now go ahead and run these tasks.
Mmm nice.
OK let's see what it did.
OK so this script will run a few basic commands.
This is the echo thing that we added in.
Right then the next thing we wanted to know which directory we are in we are in this directory then
l s l s will list all the directories and files inside of my current working directory and those files
are basic task and hello world.
So it's this own file that I just ran the command and then who am I.
That's my name.
I am logged in as myself.
Date.
This is the date it's telling it what date is today and calendar is the calendar that it is output Now
the last one is.
Hey what happened to touch a b c.
Did it create that file.
I am sure it has but why didn't you see in here when it was listing dat files.
Very good question.
Now let's go back to a sequence remember the script works in a sequence in an order of first things
first.
So by the time touch a b c it hit that touch a b c it ran ls command before that so that's why you didn't
see it.
So now if you run it you will see your three files in there.
So without running the script just to LS minus L and you'll see in there.
There you go c c.
So let's mysell TR TR will list everything in a date format.
When was last created.
So if you see it has created a b and c files.
So this is how we do our basic tasks so if you are going through all that hassle every day and you want
to automate them through one simple basic tasks you could do that simply this way.
Again I'd like to keep things neat and clean.
So what I would do is put at go in every line.
Go echo and echo and then at the bottom of say Echo and off script ice.
Welcome you guys probably knows hate Imraan just did something.
I did it purposely.
I just put it down wrong.
C'mon And let's see what the error message comes up.
That's the basic tasks.
And it did everything I asked for.
Now you see as it has given me those ABC files as well.
And now at the bottom it says the line 21 command not found.
OK.
So something went wrong with the script.
Now this is how you troubleshoot a script.
I wanted to code that troubleshooting part right here at the beginning because every time you write
a script there is always always a chance I will say I'm not going to say there's very little chance.
We're humans we make mistake there's always chance that you fat finger some of the command or you make
a mistake then the script doesn't run.
Then how do you troubleshoot Well the Linux operating system or the scripting shells are smart enough
to tell you where the problem is.
So it's telling you that the script is this and in line 21 there is a command called E C H that command
now found you want to run that command.
I understand but there is no such thing as command.
Why try it just by simply typing it.
You add there is no such command.
So we know that in line 21 in this group there is a mistake and we have to fix it.
And the way I do would is I vi the script and I will Let's see if I'm right here or anywhere I'll just
do colon 21.
This will bring me exactly to that line where I was complaining.
They go so it brought me right to the line and I see ha oh ok I'm sorry I made a mistake.
I left out.
Oh now will run it for effect.
Perfect.
I fixed my mistake.
That is perfect.
That's how we learn.
So when you hit enter again and run the script and they go it is giving you everything that you asked
for.
And at the end is telling you and of script.
So it's it's again it's a good practice that you output that what exactly the script will do at the
beginning that will tell the user hey this script will run a few basic commands and will draw that out
on the screen.
And when the script finishes it should say end of script perfect.
So that's how we do simple basic tasks using scripting language.
So try it out try different commands in there.
There are so many commands on X I want you to try them out one by one and see how you could automate
a few simple tasks a few daily tasks.