1

We have script file FileChecker.sh where it checks whether file exists or not

FileChecker.sh content:

#!/bin/ksh
FILE=$1
FILE2=$2
if [[ "$FILE" == "" || "$FILE2" == "" ]] ; then
    echo "[ERROR] if Invalid input to $0 \n"
elif [[ ! -f $FILE||  ! -f $FILE2 ]] ; then
    echo "[ERROR] elif Invalid input to $0 \n"
else
   echo "In Else"
fi

We are logged in as user aaa. Running the script as follows:

[aaa@servername cfg]$ ./FileChecker.sh /tmp/lib/my.properties /tmp/lib/my.ear

and we are passing the file names with location as the input to the script and the permissions are 755 on the input files. we ran the FileChecker.sh with user aaa and the script executed and it found the file but when we execute the FileChecker.sh file with user www then the script is unable to locate the input files and prints [ERROR] elif Invalid input to FileChecker.sh.

Following are the details about file permissions and the default Shell for both the users. default shell for aaa is /bin/ksh and for www it is /bin/bash.

[aaa@servername lib]$ cd /tmp/lib
[aaa@servername lib]$ ls -lrt
-rwxr-xr-x 1 aaa aaagroup      175 Apr 16 11:12 my.properties
-rwxr-xr-x 1 aaa aaagroup 14354727 Apr 16 11:12 my.ear


[aaa@servername lib]$ cat /etc/passwd | grep aaa
aaa:x:129822:602:aaa, env.xyz Hostgroup, Id, F, Num:/home/aaa:/bin/ksh

[aaa@servername lib]$ cat /etc/passwd | grep www
www:x:13113:602:www, Hostgroup, Id, F, Num:/home/www:/bin/bash

How to I get it working by running as www user.

3
  • 1
    What are the permissions on the directory /tmp/lib? perhaps it is not executable for user www Apr 16, 2019 at 19:59
  • It is drwx------ 2 aaa aaagroup 4096 Apr 3 09:47 lib Apr 16, 2019 at 21:24
  • That's your problem: user www cannot read the directory, so the -f $FILE test fails. You need to chmod 755 /tmp/lib (or use setfacl to specifically give user www extra permissions on the directory if you don't want to open it up to the world) Apr 16, 2019 at 22:01

1 Answer 1

2

What you're observing is is not a result of the users' different login shells.

The issue is that your www user does not have execute permission on the containing directory /tmp/lib (and so can't traverse it in order to test the file properties within it).

Ex. given

$ namei -l /tmp/lib/my.properties 
f: /tmp/lib/my.properties
drwxr-xr-x root        root        /
drwxrwxrwt root        root        tmp
drwxrw-r-- steeldriver steeldriver lib
-rwxr-xr-x steeldriver steeldriver my.properties

then

$ sudo -u testuser ./FileChecker.sh /tmp/lib/my.properties /tmp/lib/my.ear
[ERROR] elif Invalid input to ./FileChecker.sh \n

but

$ chmod o+x /tmp/lib
$ sudo -u testuser ./FileChecker.sh /tmp/lib/my.properties /tmp/lib/my.ear
In Else

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .