Bug in Lab - "Shell Scripting" - Q3

Hi,
There seems to be another bug in Lab “Shell Scripting” unfortunately. I verified every filename and setting at least 3 times and it should be correct.
Also I have tried according to solution, but it is still not working at all:

[bob@centos-host ~]$ ls -la
total 44
drwx------ 1 bob  bob  4096 Dec 30 07:43 .
drwxr-xr-x 1 root root 4096 Sep  8 17:15 ..
-rw-r--r-- 1 bob  bob    18 Feb 15  2024 .bash_logout
-rw-r--r-- 1 bob  bob   141 Feb 15  2024 .bash_profile
-rw-r--r-- 1 bob  bob   492 Feb 15  2024 .bashrc
drwxr-xr-x 3 bob  bob  4096 Dec 30 07:41 .cache
-rw------- 1 bob  bob  1205 Dec 30 07:41 .viminfo
-rw-r--r-- 1 bob  bob   158 Dec 30 07:43 archive.tar.gz
drwxr-xr-x 2 bob  bob  4096 Dec 30 07:36 dir1
-rwxr-xr-x 1 bob  bob    74 Dec 30 07:41 script.sh
[bob@centos-host ~]$ cat script.sh
#!/bin/bash
tar czf /home/bob/archive.tar.gz --directory=/home/bob/dir1 .

@Hi @kodekloud1761

What do you see when you extract the archive.tar.gz?

@kodekloud1761 The task says: “The script should archive the directory called dir1” not “the contents of a directory”, so why are you using --directory=/home/bob/dir1 . instead of simply providing dir1 as an argument for tar command?

I just checked.
I can see the contents of dir1 directory in my tar:

[bob@centos-host ~]$ tar tf archive.tar.gz 
./
./file1
./file3
./file2
[bob@centos-host ~]$ ls -la dir1/
total 8
drwxr-xr-x 2 bob bob 4096 Dec 30 11:02 .
drwx------ 1 bob bob 4096 Dec 30 11:05 ..
-rw-r--r-- 1 bob bob    0 Dec 30 11:02 file1
-rw-r--r-- 1 bob bob    0 Dec 30 11:02 file2
-rw-r--r-- 1 bob bob    0 Dec 30 11:02 file3
[bob@centos-host ~]$ 

I just tried with just using the directory and not the directory option, but still does not work:

[bob@centos-host ~]$ cat script.sh 
#!/bin/bash
tar czf /home/bob/archive.tar.gz /home/bob/dir1
[bob@centos-host ~]$ tar tf archive.tar.gz 
home/bob/dir1/
home/bob/dir1/file1
home/bob/dir1/file3
home/bob/dir1/file2
[bob@centos-host ~]$ 

Also tried another way, but it is still shown as wrong:

[bob@centos-host ~]$ tar tf archive.tar.gz 
dir1/
dir1/file1
dir1/file3
dir1/file2
[bob@centos-host ~]$ cat script.sh 
#!/bin/bash
tar czf /home/bob/archive.tar.gz dir1
[bob@centos-host ~]$ 

Also directly copied and pasted the solution, which still does not work:

[bob@centos-host ~]$ ls -la
total 40
drwx------ 1 bob  bob  4096 Dec 30 11:30 .
drwxr-xr-x 1 root root 4096 Sep  8 17:15 ..
-rw-r--r-- 1 bob  bob    18 Feb 15  2024 .bash_logout
-rw-r--r-- 1 bob  bob   141 Feb 15  2024 .bash_profile
-rw-r--r-- 1 bob  bob   492 Feb 15  2024 .bashrc
drwxr-xr-x 3 bob  bob  4096 Dec 30 11:05 .cache
-rw------- 1 bob  bob  1925 Dec 30 11:30 .viminfo
drwxr-xr-x 2 bob  bob  4096 Dec 30 11:02 dir1
-rwxr--r-- 1 bob  bob    40 Dec 30 11:30 script.sh
[bob@centos-host ~]$ cat script.sh 
#!/bin/bash
tar acf archive.tar.gz dir1
[bob@centos-host ~]$ ./script.sh 
[bob@centos-host ~]$ ls -la
total 44
drwx------ 1 bob  bob  4096 Dec 30 11:30 .
drwxr-xr-x 1 root root 4096 Sep  8 17:15 ..
-rw-r--r-- 1 bob  bob    18 Feb 15  2024 .bash_logout
-rw-r--r-- 1 bob  bob   141 Feb 15  2024 .bash_profile
-rw-r--r-- 1 bob  bob   492 Feb 15  2024 .bashrc
drwxr-xr-x 3 bob  bob  4096 Dec 30 11:05 .cache
-rw------- 1 bob  bob  1925 Dec 30 11:30 .viminfo
-rw-r--r-- 1 bob  bob   158 Dec 30 11:30 archive.tar.gz
drwxr-xr-x 2 bob  bob  4096 Dec 30 11:02 dir1
-rwxr--r-- 1 bob  bob    40 Dec 30 11:30 script.sh
[bob@centos-host ~]$ tar tf archive.tar.gz 
dir1/
dir1/file1
dir1/file3
dir1/file2
[bob@centos-host ~]$

Hi @kodekloud1761

Thanks for reporting this, I verified the lab and it looks like there’s a bug in the grader that is failing even the script provided in the solution.

I’ve raised a ticket for this and I’ll make sure you’re informed when it’s fixed.

1 Like

Hi @john_doe @kodekloud1761

The issue with this lab is fixed; it works as expected.

Thanks, fo your support and patience.