Skip to content

Instantly share code, notes, and snippets.

@unique1984
Created February 24, 2019 12:06
Show Gist options
  • Select an option

  • Save unique1984/44ee955ee7ce1149a18d7034a6fefa25 to your computer and use it in GitHub Desktop.

Select an option

Save unique1984/44ee955ee7ce1149a18d7034a6fefa25 to your computer and use it in GitHub Desktop.
Check the permissions of given location/file
#!/usr/bin/env bash
if [ -z "$1" ]; then
# echo "Pick an element!"
# exit
baseElement="$PWD/"
else
baseElement="$1"
fi
if [ -z "$2" ];then
find "$baseElement" -maxdepth 1 -type d -exec stat -c '%a %U %G %n' {} \;
find "$baseElement" -maxdepth 1 -type f -exec stat -c '%a %U %G %n' {} \;
elif [ "$2" = "r" ];then
find "$baseElement" -type d -exec stat -c '%a %U %G %n' {} \;
find "$baseElement" -type f -exec stat -c '%a %U %G %n' {} \;
else
echo -e "2nd argument must be 'r' for recursive!"
exit
fi
sudo cp permissionsCheck.sh /usr/bin
chmod +x /usr/bin/permissionsCheck.sh
# location A (stable running machine)
permissionsCheck.sh /var -r | awk {'print "chmod -R "$1" "$4" && chown -R "$2":"$3" "$4'} > checkedPermissions.list


# 1. Open the machine using recovery consol (Debian Installation media in my case)
# 2. Select and open console /dev/sda2 (in my machine, "/ folder")
# 3. give the command -> "bin/bash" and you don't have to do things without gnucoreutils
# 4. chmod -R 777 /var
# 5. below command :)

# location B (crashed[ chown -R www-data:www-data /var] machine) !!! Do not use inline command !!!

cat checkedPermissions.list | bash 

# ignore the errors, at least you can use your system.

** It works for me but i know i have to format my machine. **

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment