Hi everyone! I'm hoping to get some help with an annoying issue I'm having. I'm attempting to run a Bash script via Cron to create Restic backups, but I'm running into a permission error. Specifically, it's stating: 'Line 60: /var/tmp/restic_backup.pid: Permission denied'. I've double-checked that the /var/tmp/ directory has the correct permissions set (drwxrwxrwt 16 root root 4096 Jan 20 10:50 /var/tmp). The cron job is executed by the right user, 'poan'. I've also tried redirecting the script to save the PID file in alternate directories like /tmp/ or /home/poan/tmp/, yet the error keeps occurring. Any insight or troubleshooting steps would be greatly appreciated! Thanks in advance!
5 Answers
I've noticed that running commands like `namei -long /var/tmp/` can provide detailed insights into your file permissions. It might reveal if there are any underlying issues you're not aware of. You can also check for more specific access control lists using `getfacl /var/tmp/`.
You might want to try using 'flock' to manage lock files—this helps prevent the script from running again while it's still active. You could structure your command like this: `/path/to/flock -n /path/to/script.sh /path/to/script.sh`. It worked for me in similar situations!
It sounds like the PID file can't be created due to permissions. Have you tried removing any existing PID files? Sometimes stale PID files can cause issues. If the permissions are correct, you should be able to delete it too.
I thought of that too, but the PID file isn’t being created in the first place, which is the main issue. It seems linked to the denied permissions from cron.
From checking the logs, it shows: 'Keine neuen Backups erstellt. Keine Benachrichtigungen notwendig.' and the permission error on line 60. It also mentions checks against the server. You may want to check if other advanced controls on the filesystem are affecting access.
What exactly does line 60 of your script look like? And it might help to add this command just above it: `ls -ld /var/tmp /var/tmp/restic_backup.pid` to see the current permissions and owner for that PID file.
Here's the part of the script related to the PID file:
`PID_FILE="/var/tmp/restic_backup.pid"`
It checks for an existing PID file before running the script.
I tried using 'flock' too, but I got the same permission issue. The error message was: '/home/poan/Dokumente/Scriptbackup/restic_backup.lock: Keine Berechtigung'.