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.

  • 1
    What are the permissions on the directory /tmp/lib? perhaps it is not executable for user www – steeldriver Apr 16 at 19:59
  • It is drwx------ 2 aaa aaagroup 4096 Apr 3 09:47 lib – santosh Damasani Apr 16 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) – glenn jackman Apr 16 at 22:01
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.