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. **