File permissions
Trying to write a short script that will tell me whether the permissions for 2 files, whose names are given as arguments to the script, are identical. If the permissions are the same, output the common permission field. If they are different, I need to output each file name followed by its permission field. I've been trying to use the cut command but seem to be missing something. Any suggestions would be appreciated. Thanks,
Al |
This is kinda hacky but it's short and simple to understand and doesn't use many tools.
Code:
#!/bin/bash |
Thanks for the info but not quite what I was looking for. Here is what I've been working on:
#!/bin/bash # Compare file permissions #========================= FILENAME=${1} FILENAME1=${2} if [ "${FILENAME}" = "" ] || [ "${FILENAME1}" = "" ] then echo "Please specify first file and press [Enter]:" read ${1} >> file3 echo "Please specify second file and press [Enter]:" read ${2} >> file3 exit fi MODE=$(stat --format=%a ${FILENAME}) MODE1=$(stat --format=%a ${FILENAME1}) #Uncomment and comment above for drwxr-xr-x format #MODE=$(stat --format=%A ${FILENAME}) #MODE1=$(stat --format=%A ${FILENAME1}) if [ "${MODE}" = "${MODE1}" ] then echo "Both files have permissions of ${MODE}" else echo "${FILENAME} Permissions are ${MODE} : ${FILENAME1} Permissions are ${MODE1}" fi I can get the user to input the files they wish to compare but it dies after that. AL |
Just remove the exit above the fi
|
Quote:
change that |
Hi,
here it is. Code:
#!/bin/bash |
Thanks for the help folks. Even though I was "looking" at it, I missed the "exit". Must of had a senior moment that lasted longer than normal. Works as advertised.
|
If you add
set -xv as the 2nd line of the script, you would have been able to watch it run each cmd. |
All times are GMT -5. The time now is 11:56 PM. |