1

.The issue is my id 'aaa' can read only the file name and not the contents inside it when I log in with my id "aaa". So to read the contents I have to switch to another user "bbb" which is having permission to read the contents in that file by using the below command:

pbrun /bin/su - bbb

to automate the above manual work I have written a script to check everyday whether a job file posted or not. How to use the above command inside my script which is executed under my id 'aaa'?

#!/bin/ksh
fname = /home/job/file1.log
#this is the path where file1.log will be posted everyday
var =$(grep 'job finished successfully ' $fname )
# my id 'aaa' is not having  privilege to read file contents only
# id 'bbb' is having the privilege so when i execute the script with
# my id the above line wont work .

if [ -e "$fname"] && [! -z "var"]

    echo " $fname has posted successfully " >>wa.txt
    mail -s "File  ALERT" abc@aaa.com <wa.txt
else
    echo " $fname has not posted " >>wa.txt
    mail -s "File  ALERT" abc@aaa.com <wa.txt   
fi

rm wa.txt 2>ni.txt

i tried below option but it did not work .

#!/bin/ksh
pbrun /bin/su - bbb

rest of the script ....

  • pbrun and su do the same thing. Both change the effective user, so just use pbrun directly. "pbrun -u bbb command" to run the commands which need to be run as user bbb. – ColinSeligSmith Feb 29 '16 at 14:27
  • if you have the right change your user id to bbb, according to the powerbroker role definitions, var =$(pbrun -u bbb "grep 'job finished successfully '" $fname ) should work (please test how the quotation marks work under pbrun. I haven't used it for more than 10 years now and forgot the syntax) – MelBurslan Feb 29 '16 at 14:35
  • Is an internal ssh an option? – Fiximan Feb 29 '16 at 14:50
  • yes first i login with my id 'aaa' then i have to ssh "server name " then i have to execute the above script . – star Feb 29 '16 at 14:53
  • I such cases better to add users in same group and add group read/write permissions to the logfile – user158847 Feb 29 '16 at 17:17

Your Answer

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

Browse other questions tagged or ask your own question.