Bash Script Task Review Error -

All tasks are recorded, so we can review them. Keep going through the tasks and this task will appear again, don’t worry. :slight_smile:

Thanks,
KodeKloud Support

Oh! I see.
Alright! I will wait for another task to assign.

Thanks again for your support.

Hi @Vitor .

Today I got this task again and it failed me again.

It seems that there is some problem in the task review algorithm or whatever it is called.

After running my script, I logged out of the AppServer 3 and logged In to the Nautilus Backup server to verify the file and, it was right there.
Then I clicked on the Check Task button and it failed me.

I don’t understand what is happening. Even if I put a Request Review on the task, there is no sense because the Task verification system has gone haywire.

Please look into this.

@Tej-Singh-Rana
Hi Tej,
If possible please check the reason behind this.

Thanks & regards,
Avni Maheshwari

Hi @avnimahesh ,
Can you please share the review link? btw don’t worry about the points. If it’s a validation issue then I will mark pending for you. But at least give us the chance to review it.

Regards,
KodeKloud Support

Sure @Tej-Singh-Rana .

Here is the Review link to the task - KodeKloud Engineer | Real Project Tasks on Real Systems

I do not worry about the points, its just that I am getting confused if I am performing the task correctly or not.
Also, thank you for doing this for me.

Thanks & regards,
Avni Maheshwari

Hi @avnimahesh ,
You are doing it correctly but we are expecting this from the sudo user, not from the root user of app server3.
Did you read this line?

Please make sure the script won't ask for a password while copying the archive file. Additionally, the respective server user (for example, tony in the case of App Server 1) must be able to run it.

You should have to run that script from the banner user and without interruption.

Regards,
KodeKloud Support

@Tej-Singh-Rana

Okay. So yes, I created and ran the script from the root user on App Server 3 but it is not mentioned anywhere in the question to perform the tasks with the Normal user only. So even if the files that I created have a root ownership but I have added ‘rwx’ permission for other users as well. So anybody could access those files.

For the script to not ask for password, I did the following before running the script:

  1. ssh keygen (Generated keygen for App Server 3)
  2. ssh-copy-id clint@stbkp01 (Copied the keygen to Nautilus Backup server)

After all these things, I logged out of App S 3 and logged in to Nautilus backup server to check for the file, and it was there.
Then I logged out of the Backup Server and logged in as tony@stapp01 to check if tony is able to access and run the files, and he was but the task kept failing me.

Let me know where I am wrong in this.

Thanks & regards,
Avni Maheshwari

image-421

Yes @Tej-Singh-Rana
I read point number d. very carefully and the commands I used, allows the script to run and execute successfully without asking for the password.
Now let me know if you have a solution or a rectification of this problem.
My steps are correct and I’m confident about it.

Hi again.

Is there something happening at the back-end?

I haven’t received any task in the past 72+ hours.

Hi,
Sorry for the delayed response.
So banner user also can run that script without facing any permission issues?
btw I marked this task pending for you. Please try from the sudo user.
Give it a try and let me know.

Regards,

Do the same steps again from the root user and make the script executable and after that run it from the sudo user of that app server (Example:- app server01, it’s tony).
Let me know if you are able to run the script successfully.

Regards,

Hi @Tej-Singh-Rana

I did all the steps even verified the zip archive on my own but the task failed still.

Here is what I did:

Logged -in to App Server 01 - ssh tony@stapp01

Changed to root user - sudo -i and then performed the below steps.

  1. Created the script in /scripts on App Server 1 - vi touch /script/news_backup.sh

Commands in the script:
zip /backup/xfusioncorp_news.zip -r /var/www/html/news
scp /backup/xfusioncorp_news.zip clint@stbkp01:/backup

  1. Made the script executable - chmod +x /script/news_backup.sh
  2. Generated ssh keygen and copied keygen to Nautilus Backup server so that the script won’t ask for password - a) ssh-keygen b) ssh-copy-id clint@stbkp01
  3. Finally, ran the script - sh /script/news_backup.sh

VERIFICATION

  1. Logged in to App Server 3 to check if he is able to execute the .zip file or not - ssh banner@stapp03
  2. Then ssh into Nautilus Backup server from App Server 3 - ssh clint@stbkp01
  3. Changed the directory to /backup to access .zip file - cd /backup

Below image shows points 1, 2 and 3:

  1. Checked if zip package is installed or not - rpm -q zip
  2. Installed zip using YUM - sudo yum install zip -y
  3. Unzipped the .zip file, changed into /var/www/html/news dir and cat the output of index.html -
    a) unzip xfusioncorp_news.zip b) cd /var/www/html/news c) cat index.html
    → Output of index.html
  4. I also deleted the var dir from /backup so that the task may not fail again - rm -rf var/

Below image shows points 5,6, and 7.

Logged out of App Server 3 and clicked on the Check Task button.

See below image -

Did you run the script from the tony user? Did it work?

Oh god! If Banner user on App Server 3 is able to run the file, tony user will have no problems at all in running, extracting or unzipping the file.

I added an executable (x) permission for others on the .zip file which means, other than File owner and group owner, other people could also access and open the file.

I don’t know what is being so hard to understand, my steps or the fault in KodeKloud’s system.

I am checking with the given steps. I will share updates after some time.

Regards,

Please find the attached screenshot.

My mistake. I forgot to add point #2 in my previous steps to make the .zip file executable for others.

Although I added x permission to others when you reassigned the task to me, that is the reason Banner user was able to execute the .zip file.

So the script will have the below commands:

  1. Archive the news dir - zip /backup/xfusioncorp_news.zip -r /var/www/html/news
  2. Add x permission to others - chmod o+x /backup/xfusioncorp_news.zip
  3. Finally secure copy the file - scp /backup/xfusioncorp_news.zip clint@stbkp01:/backup/

Repeat the steps again with point #2 as well and you will be able to run the .zip file from either of the three App Server Users.

Hi @avnimahesh,
I think you are not getting my point.
User tony has to enter a password each time whenever he will execute the script. This is not a passwordless setup for him.
You need to copy his public key to the backup server first by using the ssh-copy-id command. After that, he will be able to run the script without entering the password.
I think you did the same for the root user right?

In the task, we only need to copy the zip file to the respective server. We didn’t say that users have to unzip as well. So don’t require that permission change for the zip file.

Regards,

Please refer to point d in the question to understand the below points.

Point d. in the image below

image-421

I don’t think that the question is asking to make App Server users to be able to login password-less to the Backup Server.

It only says, “make sure script won’t ask for password while copying the archive file.” So in order to fulfil the password-less copying from one server to another, I had to setup a password-less ssh login between those two servers which I did.

I could have copied the public key of Tony user but I would have to perform all the tasks with SUDO privileges only right because all the directories were in the / location which a normal user is denied access to.
So instead of doing sudo sudo in every command, I simply switched the user and did all the steps.

So even if I did →
[logged in as Tony user]
sudo vi /scripts/scriptname.sh

OR

[logged in as root in App Server 1]
vi /scripts/scriptname.sh

the ownership for the script file would be root user only. So there was no sense doing all the tasks being a normal user on App Server 1.

Secondly, it says,“Additionally, the respective server user (for example, tony in case of App Server 1) must be able to run it.” ----> The question would obviously not refer to password-less login to Backup server by saying the word “run it”. The question is referring to the file which is on the backup server.

Yeah, it is a pain for the users to enter the password every time they login to the Backup Server but the question didn’t asked to make Users for password-less login to Backup Server or else it is only a single command thing to do.

So as per the above explanation, the .zip file must have an (x) permission on others so that our users from App Server 1, 2 and 3 could run the file.

Also I want to highlight something. We totally forgot the problem here while discussing.

The problem is “Kodekloud’s verification system was not able to find the .zip file copied by the script on the Backup Server.”

The problem was nowhere around what the permissions were or are users able to run the file or not.

See the picture below —

Image 1

Image 2

image

Image 3

THESE ARE THE IMAGES FROM MY FAILED TASKS.

I hope you understand.