Task Linux Bash Scripts failed task

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

thor@jump_host /$ ssh banner@stapp03The 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.
banner@stapp03’s password:
[banner@stapp03 ~]$ 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:
[root@stapp03 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 root@stapp03
The key’s randomart image is:
±–[RSA 2048]----+
| . oOX|
| o.+@o|
| . .= .|
| . . o |
| S… . . |
| .E+ * + . |
| . +oB.O o |
| +.o
Ooo |
| . =Oo |
±—[SHA256]-----+
[root@stapp03 banner]# ssh-copy-id clint@stbkp01
/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
clint@stbkp01’s password:

Number of key(s) added: 1

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

[root@stapp03 banner]# cd /scripts/
[root@stapp03 scripts]#
[root@stapp03 scripts]#
[root@stapp03 scripts]# ll
total 0
[root@stapp03 scripts]# vi news_backup.sh
[root@stapp03 scripts]# ll
total 4
-rw-r–r-- 1 root root 200 Aug 16 20:13 news_backup.sh
[root@stapp03 scripts]# chmod +x news_backup.sh
[root@stapp03 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
[root@stapp03 scripts]# exit
exit
[banner@stapp03 ~]$ cd /scripts/
[banner@stapp03 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
[banner@stapp03 scripts]$ thor@jump_host /$
thor@jump_host /$
thor@jump_host /$ ssh clint@stbkp01
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.
clint@stbkp01’s password:
[clint@stbkp01 ~]$ cd /backup/
[clint@stbkp01 backup]$ ll
total 4
-rw-r–r-- 1 clint clint 588 Aug 16 20:18 xfusioncorp_news.zip
[clint@stbkp01 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