Task Linux Bash Scripts

Hi guys,

Can someone show me where I go wrong from my solution?

+The Task content:
Production support team of xFusionCorp Industries is working on developing some bash scripts to automate different day to day tasks. One of them is to create a bash script for taking websites backup. They have a static website running on App Server 1 in Stratos Datacenter. They need to create a bash script named ecommerce_backup.sh which should accomplish below given tasks. (Also remember to place the script under /scripts directory on App Server 1)
a. Create a zip archive named xfusioncorp_ecommerce.zip of /var/www/html/ecommerce directory.
b. Save the archive in /backup/ on App Server 1. This is a temporary storage as backups from this location will be clean on weekly basis so we also need to save this backup archive on Nautilus Backup Server.
c. Copy the created archive to Nautilus Backup Server server in /backup/ location.
d. Please make sure script won’t ask for password while coping the archive file also respective server user (for example tony in case of App Server 1) must be able to run it.

+What I did

  1. Create SSH key without password
    ssh-keygen -t rsa -b 4096 -C “clint@stbkp01”
    cat /tony/.ssh/id_rsa.pub | ssh clint@stbkp01 ‘cat >> .ssh/authorized_keys’

ssh clint@stbkp01 => this works without asking for password
2. Create scripts
zip -r /scripts/xfusioncorp_ecommerce.zip /var/www/html/ecommerce
mv /scripts/xfusioncorp_ecommerce.zip /backup/
scp /backup/xfusioncorp_ecommerce.zip clint@stbkp01:/backup/

chmod +x /scripts/ecommerce_backup.sh
3. Verify
sh /scripts/ecommerce_backup.sh

[tony]
/backup/xfusioncorp_ecommerce.zip => checked
[clint]
/backup/xfusioncorp_ecommerce.zip => checked

Edit:
After the 3rd times retry, the task responses Succeed. I still dont know how the verification works. An explanation would be much appreciated.

Thanks for reading my issue & Sorry for my bad english.

1 Like

@kahntran if you can share the screenshot of the error you are getting, it will be easier to get assistance.

@Salim I am glad you are looking into this, because I completed this task before with the same steps and it was successful.

Now it fail because it believe the file is missing on the backup server.
But it is not as you can see from the screenshot.

1 Like

@Joe your .zip file name is wrong, you used xfusioncorp_media.zip instead of xfusioncorp_ecommerce.zip. I think that’s why it can’t not find the file.

@Inderpreet or @mmumshad I would appreciate someone else correct this result. @Salim your answer is not correct, the names are changed after each attempt. The screen shot indicate that I used the correct name. The screen shot also showed that I verify the file was copied and present before I submit my results. ecommerce.zip was not assigned in my task.
Also, this is a task that I had completed multiple times when the system was having problem a few days ago.

Ok @Joe I was just trying to help.

can we see your script file? may be error in your script?

Hi @Tej-Singh-Rana @Inderpreet

I did the task Linux backup scripts but it failed. It did test it before submitting and it did work fine(without asking for password). Can you please check where it went wrong.

Task Desription:

Production support team of xFusionCorp Industries is working on developing some bash scripts to automate different day to day tasks. One of them is to create a bash script for taking websites backup. They have a static website running on App Server 3 in Stratos Datacenter. They need to create a bash script named media_backup.sh which should accomplish below given tasks. (Also remember to place the script under /scripts directory on App Server 3)

a. Create a zip archive named xfusioncorp_media.zip of /var/www/html/media directory.

b. Save the archive in /backup/ on App Server 3. This is a temporary storage as backups from this location will be clean on weekly basis so we also need to save this backup archive on Nautilus Backup Server.

c. Copy the created archive to Nautilus Backup Server server in /backup/ location.

d. Please make sure script won’t ask for password while coping the archive file also respective server user (for example tony in case of App Server 1) must be able to run it.

What I did:

sudo yum install -y zip unzip

ssh-keygen

ssh-copy-id -i /home/banner/.ssh/id_rsa.pub clint@stbkp01

cd /scripts

sudo vi media_backup.sh

My Script:

#!bin/bash

sudo zip -r /backup/xfusioncorp_media.zip /var/www/html/media

sudo scp -i /home/banner/.ssh/id_rsa /backup/xfusioncorp_media.zip clint@stbkp01:/backup/xfusioncorp_media.zip

Hello @Inderpreet @Tej-Singh-Rana

Any suggestions please.

Hi guys,
@Joe @kahntran
I think you should do sudo scp /backup/xfusioncorp_commerce.zip clint@stbkp0:/backup/xfusioncorp_commerce.zip rather than scp /backup/xfusioncorp_commerce.zip clint@stbkp0:/backup/

It will work only one time when system will boot up again if you run this script with sudo privilege it will ask the password so script is not configured according for that. That’s why task marked as failed. Avoid to use sudo or if adding then make it according for it.

I passed it very easily.

You have to allow tony from appServer 1 to be able to ssh the appServer3 without password and tony must be able to execute the script also.

I put in the same script the scp of the backup directly to the backup server.