Task Linux Bash Scripts failed task

The file was created successfully but I felt something is wrong with the server itself. Please see below:

[email protected]_host /$ ssh [email protected] authenticity of host 'stapp03 (172.16.238.12)' can't be established.

ECDSA key fingerprint is SHA256:SySamszyWhhLGFiybhGBqfrr8g55wS/3e37ZpBOvICs.
ECDSA key fingerprint is MD5:6d:31:18:2a:f9:07:f3:29:dd:0a:d3:1f:6e:04:0a:db.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘stapp03,172.16.238.12’ (ECDSA) to the list of known hosts.
[email protected]’s password:
[[email protected] ~]$ sudo su

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for banner:
[[email protected] banner]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:rFuW3VLi5tt4kjPYp4XzwYdpHTGllVBaTGUa9tWQyKo [email protected]
The key’s randomart image is:
±–[RSA 2048]----+
| . oOX|
| [email protected]|
| . .= .|
| . . o |
| S… . . |
| .E+ * + . |
| . +oB.O o |
| +.o
Ooo |
| . =Oo |
±—[SHA256]-----+
[[email protected] banner]# ssh-copy-id [email protected]
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_rsa.pub”
The authenticity of host ‘stbkp01 (172.16.238.16)’ can’t be established.
ECDSA key fingerprint is SHA256:AZNVJL/pbLhaqfzpgif6JE6hOkm3840KmFqm5OfO42c.
ECDSA key fingerprint is MD5:73:64:56:c8:f1:ea:28:59:ac:36:1e:56:97:18:6b:fc.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install thenew keys
[email protected]’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘[email protected]’”
and check to make sure that only the key(s) you wanted were added.

[[email protected] banner]# cd /scripts/
[[email protected] scripts]#
[[email protected] scripts]#
[[email protected] scripts]# ll
total 0
[[email protected] scripts]# vi news_backup.sh
[[email protected] scripts]# ll
total 4
-rw-r–r-- 1 root root 200 Aug 16 20:13 news_backup.sh
[[email protected] scripts]# chmod +x news_backup.sh
[[email protected] scripts]# ./news_backup.sh
adding: var/www/html/news/ (stored 0%)
adding: var/www/html/news/.gitkeep (stored 0%)
adding: var/www/html/news/index.html (stored 0%)
xfusioncorp_news.zip 100% 588 1.2MB/s 00:00
[[email protected] scripts]# exit
exit
[[email protected] ~] cd /scripts/ [[email protected] scripts] ./news_backup.sh
updating: var/www/html/news/ (stored 0%)
updating: var/www/html/news/.gitkeep (stored 0%)
updating: var/www/html/news/index.html (stored 0%)
xfusioncorp_news.zip 100% 588 1.0MB/s 00:00
[[email protected] scripts] [email protected]_host /
[email protected]_host / [email protected]_host / ssh [email protected]
The authenticity of host ‘stbkp01 (172.16.238.16)’ can’t be established.
ECDSA key fingerprint is SHA256:AZNVJL/pbLhaqfzpgif6JE6hOkm3840KmFqm5OfO42c.
ECDSA key fingerprint is MD5:73:64:56:c8:f1:ea:28:59:ac:36:1e:56:97:18:6b:fc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘stbkp01,172.16.238.16’ (ECDSA) to the list of known hosts.
[email protected]’s password:
[[email protected] ~] cd /backup/ [[email protected] backup] ll
total 4
-rw-r–r-- 1 clint clint 588 Aug 16 20:18 xfusioncorp_news.zip
[[email protected] backup]$

Here is my script:

#!/bin/bash
cd /var/www/html/news
sudo zip -r xfusioncorp_news.zip /var/www/html/news
sudo cp /var/www/html/news/xfusioncorp_news.zip /backup/
sudo scp -r /backup/xfusioncorp_news.zip [email protected]:/backup

Can you please check why it was marked as failed?

hello, aeldemerdash
You don’t need to use sudo. This post will clear your doubt.

1 Like

Thanks a lot @Tej-Singh-Rana

Hi @Inderpreet,

I got the task for the second time and confirmed everything is Ok this time and the file was copied to /backup folder on backup server as you can see from the screenshot. This shouldn’t be normal that the task fails again. please check.

Hi @Tej-Singh-Rana

Can you please have a look?

Thanks in advance

Hi All,

Can I have an answer please?

@aeldemerdash Seems like you created and ran the script from root user however it was supposed to be done by sudo user (e.g tony for stapp01) .

yes, that what happened. the file is there though :slight_smile:

Anyway, thank you