d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help With A Simple Bash Script > Tip 50fg
Add Reply New Topic New Poll
Member
Posts: 3,295
Joined: Jan 9 2012
Gold: 249.00
May 8 2016 01:17pm
I need a bash shell script that will read /etc/shadow and print "I can read the file." if you can or print "I can not read the file." If you cannot.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 8 2016 01:48pm
Code
abduct ~ $ sudo chmod 750 atest
abduct ~ $ cat atest
cat: atest: Permission denied
abduct ~ $ ./t.sh atest
I do not have permissions to read this file
abduct ~ $ sudo ./t.sh atest
I have permissions to read this file
abduct ~ $ stat atest
File: 'atest'
Size: 13 Blocks: 8 IO Block: 4096 regular file
Device: 809h/2057d Inode: 599083080 Links: 1
Access: (0750/-rwxr-x---) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-05-08 14:55:46.710654979 -0500
Modify: 2016-05-08 14:55:44.722654883 -0500
Change: 2016-05-08 14:56:11.918656199 -0500
Birth: -
abduct ~ $ cat t.sh
if [ -r "$1" ]
then
echo "I have permissions to read this file"
else
echo "I do not have permissions to read this file"
fi


http://www.tldp.org/LDP/abs/html/fto.html
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll