Linux BAsh Scripts - Failed

Hi @Inderpreet @kodekloud-support3

Linux Bash script was failed with “xfusioncorp_media.zip is not found on backup server”. I have also setup passwordless authentication for other server user like app02 app03 to run the scripts without any password. I did everything right, not sure why it got failed. Also i have

Could you please check and let me know what went wrong.

@Rapa If you read the question carefully there is a point:

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.

I think you setup the passworless access from root user (on stspp01) to clint user on backup server however tony user must be able to run the script on app server 1.

Thankyou @Inderpreet

ot@stapp02 ~]# cd /scripts/
[root@stapp02 scripts]# vi official_backup.sh
[root@stapp02 scripts]# ssh keygen -t rsa
ssh: Could not resolve hostname keygen: Name or service not known
[root@stapp02 scripts]# sudo 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:pkD0pYYdMNJkYV2u/I85Mr/nQvkotv8F4CDUiX3tiFc root@stapp02The key's randomart image is:
+---[RSA 2048]----+
|  .oXB.oo.       |
|   *o===. E      |
|    + *oo+       |
|   . +.+o..      |
|    . o.S..      |
|     . +o  .     |
|      ...o  .    |
|      = ++o.     |
|     ..B*B+      |
+----[SHA256]-----+
[root@stapp02 scripts]# sudo ssh-copy-id steve@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:GwYeLgfTP9/0FChuujIkP9mJnKZMG11uTszEDSNYngY.
ECDSA key fingerprint is MD5:5b:ce:e4:12:50:fb:ed:04:55:19:ae:8a:c6:da:e1:a1.
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 the new keys
steve@stbkp01's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'steve@stbkp01'"
and check to make sure that only the key(s) you wanted were added.

[root@stapp02 scripts]# ls
official_backup.sh
[root@stapp02 scripts]# su steve
[steve@stapp02 scripts]$ ls
official_backup.sh
[steve@stapp02 scripts]$ ./official_backup.sh
bash: ./official_backup.sh: Permission denied
[steve@stapp02 scripts]$ sudo ./official_backup.sh
[sudo] password for steve:
sudo: ./official_backup.sh: command not found
[steve@stapp02 scripts]$ vi official_backup.sh
[steve@stapp02 scripts]$ sudo ./official_backup.sh
sudo: ./official_backup.sh: command not found
[steve@stapp02 scripts]$ sudo sh ./official_backup.sh
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
epel/x86_64/metalink                                              |  32 kB  00:00:00
 * base: mirror.plustech.de
 * epel: mirrors.n-ix.net
 * extras: linux.darkpenguin.net
 * remi-php72: mirror.23media.com
 * remi-safe: mirror.23media.com
 * updates: mirror.alpix.eu
base                                              | 3.6 kB  00:00:00
epel                                              | 4.7 kB  00:00:00
extras                                              | 2.9 kB  00:00:00
remi-php72                                              | 3.0 kB  00:00:00
remi-safe                                              | 3.0 kB  00:00:00
updates                                              | 2.9 kB  00:00:00
(1/9): base/7/x86_64/group_gz                                              | 153 kB  00:00:00
(2/9): extras/7/x86_64/primary_db                                              | 190 kB  00:00:00
(3/9): epel/x86_64/updateinfo                                              | 1.0 MB  00:00:00
(4/9): base/7/x86_64/primary_db                                              | 6.1 MB  00:00:00
(6/9): epel/x86_64/primary_db                                              45% [=============================(5/9): epel/x86_64/group_gz                                              |  95 kB  00:00:00
(6/9): updates/7/x86_64/primary_db                                              | 168 kB  00:00:00
(8/9): remi-php72/primary_db                                               67% [==============================(7/9): epel/x86_64/primary_db                                              | 6.8 MB  00:00:00
(9/9): remi-safe/primary_db                                                89% [==============================(8/9): remi-php72/primary_db                                              | 236 kB  00:00:00
(9/9): remi-safe/primary_db                                              | 1.7 MB  00:00:01
Package zip-3.0-11.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package unzip.x86_64 0:6.0-21.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================
 Package                                  Arch                                      Version                       Repository                               Size
===================================================================================================================================================================================
Installing:
 unzip                                    x86_64                                    6.0-21.el7                       base                                    171 k

Transaction Summary
===================================================================================================================================================================================
Install  1 Package

Total download size: 171 k
Installed size: 365 k
Downloading packages:
unzip-6.0-21.el7.x86_64.rpm                                              | 171 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded

What did i do wrong . backup server has the file

@Inderpreet

@labheshp

Seems like on stapp02 you did all the testing from user root, as mentioned it the question did you tested it from user sudo user i.e steve in case of stapp02.

This command [steve@stapp02 scripts]$ sudo ./official_backup.sh still means you ran it using user root as you used sudo.