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.
/tmp/lib
? perhaps it is not executable for userwww
drwx------ 2 aaa aaagroup 4096 Apr 3 09:47 lib
www
cannot read the directory, so the-f $FILE
test fails. You need tochmod 755 /tmp/lib
(or usesetfacl
to specifically give user www extra permissions on the directory if you don't want to open it up to the world)