You are not logged in.
I have created a bash cleaning script which works well but I have one issue after the reboot the service won't start.
Here's the script:
#!/bin/bash
# Trash cleaning script by archifer
yes Y | sudo pacman -Sc && sudo paccache -r &&
sudo journalctl --vacuum-size=50 &&
rmlint ~/ && yes | sh ~/rmlint.sh &&
sudo rm -r ~/.cache/* &&
sudo pacman -Qtdq &&
sudo pacman -Rns $(pacman -Qtdq)clean.service
[Unit]
Description=Clean-up old pkgs and lint
[Service]
Type=oneshot
ExecStart=/home/admin/clean.sh
[Install]
WantedBy=timers.targetclean.timer
[Unit]
Description=Clean-up old pkgs and lint
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.targetThen I run
sudo systemctl enable clean.servicesudo systemctl status clean.serviceAnd at first it worked and was active but now after the reboot I get this:
systemd[437]: clean.service: Failed to execute command
systemd[437]: clean.service: Failed at step EXEC clean.service: Failed to execute command: Permission denied
systemd[1]: clean.service: Main process exited, code clean.service: Failed at step EXEC spawning /home/admin/clean.sh: Permission denied
systemd[1]: clean.service: Failed with result 'exit-clean.service: Main process exited, code=exited, status=203/EXEC
systemd[1]: Failed to start Clean-up old pkgs and lint.Last edited by archifer (2019-12-12 11:37:18)
Offline
What's the output of `stat ~/clean.sh`?
Please also edit your post to not obfuscate relevant information - your username need not be a secret, but the service file and the output clearly mismatch.
For the bash script, why are you using && at the end of every line? If you want the whole script to stop at the first failed command, just use `set -e` at the start. Also definitely get rid of those 'sudo's, they are pointless and just add another potential point of failure. There's also no need to run `pacman -Qdtq` twice, just run it once in the subshell for the removal comand:
pacman -Rsn $(pacman -Qdtq)
# or if you want to script to exit without error
pacman -Rsn $(pacman -Qdtq) || trueAlso, while it's not likely relevant to the current error, you could have trouble in the future if you have a seperate home partition.
Last edited by Trilby (2019-12-10 14:26:01)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I'm almost certain services in system mode are supposed to run as root , not as user.
Your script combines acts as root with acts as user.
I suggest you create 2 scripts : one for root and another for user.
https://wiki.archlinux.org/index.php/Systemd/User may be useful for you.
Apart from that , there's one command in your script I would never automate.
pacman -Rns $(pacman -Qtdq)I run the pacman -Qtd manually often and have found it regularly shows things I do not want to remove because I still need them (I change the install reason to explicit then to make sure they'll no longer be listed by -Qdt)
If you do want to keep this automated, atleast remove the s from pacman -Rns .
Last edited by Lone_Wolf (2019-12-10 14:30:35)
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
clean chroot building not flexible enough ?
Try clean chroot manager by graysky
Online
What's the output of `stat ~/clean.sh`?
Please also edit your post to not obfuscate relevant information - your username need not be a secret, but the service file and the output clearly mismatch.
For the bash script, why are you using && at the end of every line? If you want the whole script to stop at the first failed command, just use `set -e` at the start. Also definitely get rid of those 'sudo's, they are pointless and just add another potential point of failure. There's also no need to run `pacman -Qdtq` twice, just run it once in the subshell for the removal comand:
pacman -Rsn $(pacman -Qdtq) # or if you want to script to exit without error pacman -Rsn $(pacman -Qdtq) || trueAlso, while it's not likely relevant to the current error, you could have trouble in the future if you have a seperate home partition.
Yes I have seperate home
here's the output for the stat
stat ~/clean.sh
File: /home/admin/clean.sh
Size: 248 Blocks: 8 IO Block: 4096 regular file
Device: 805h/2053d Inode: 3407964 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ admin) Gid: ( 1000/ admin)Offline
I'm almost certain services in system mode are supposed to run as root , not as user.
Your script combines acts as root with acts as user.I suggest you create 2 scripts : one for root and another for user.
https://wiki.archlinux.org/index.php/Systemd/User may be useful for you.Apart from that , there's one command in your script I would never automate.
pacman -Rns $(pacman -Qtdq)I run the pacman -Qtd manually often and have found it regularly shows things I do not want to remove because I still need them (I change the install reason to explicit then to make sure they'll no longer be listed by -Qdt)
If you do want to keep this automated, atleast remove the s from pacman -Rns .
Thanks, I will check it.
Offline
What's the output of `stat ~/clean.sh`?
Please also edit your post to not obfuscate relevant information - your username need not be a secret, but the service file and the output clearly mismatch.
For the bash script, why are you using && at the end of every line? If you want the whole script to stop at the first failed command, just use `set -e` at the start. Also definitely get rid of those 'sudo's, they are pointless and just add another potential point of failure. There's also no need to run `pacman -Qdtq` twice, just run it once in the subshell for the removal comand:
pacman -Rsn $(pacman -Qdtq) # or if you want to script to exit without error pacman -Rsn $(pacman -Qdtq) || trueAlso, while it's not likely relevant to the current error, you could have trouble in the future if you have a seperate home partition.
I have changed the permission of clean.sh to 755 now the process gets enabled but failed to start
systemctl status clean.service
● clean.service - Clean-up old pkgs and lint
Loaded: loaded (/etc/systemd/system/clean.service; enabled; vendor preset:disabled)
Active: failed (Result: exit-code) since Tue 2019-12-10 17:05:33 EET; 15s ago
Process: 15034 ExecStart=/home/admin/clean.sh (code=exited, status=127)
Main PID: 15034 (code=exited, status=127)Offline
Well yes, that's because your script as written makes almost no sense at all as noted by the previous posts in this thread.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Well yes, that's because your script as written makes almost no sense at all as noted by the previous posts in this thread.
The idea was to launch these commands weekly
pacman -Sc
paccache -r
journalctl --vacuum-size=50
rmlint /home/admin/
sh /home/admin/rmlint.sh
pacman -R $(pacman -Qtdq)Because I do run those commands every week or twice a week to keep the system clean and I just wanted to make them automated.
Offline
What does the actual script look like atm, what is "/home/admin/rmlint.sh" (stat and content)?
"status=127" means that some command was not found.
Offline
What does the actual script look like atm, what is "/home/admin/rmlint.sh" (stat and content)?
"status=127" means that some command was not found.
rmlint is a script for cleaning broken links and leftovers lint I just installed it with `pacman -S rmlint` it works good.
Offline
I know what rmlint is, but you seem to be calling some script in your $HOME, also please answer the other question.
Offline
I know what rmlint is, but you seem to be calling some script in your $HOME, also please answer the other question.
`cleaner.sh` as in my post that is a script with the set of commands that I created personally when it is run it creates `rmlint.sh` during the clean process as per `rmlint ~/` command and then executes it. Both .sh are executable and they work if I run `sh ~/clean.sh` manually in terminal all commands are executed there are no errors and if I create a service with this script (clean.sh) I can enable that service once created `sudo nano /etc/systemd/system/clean.service` but I cannot start it after that with sudo systemctl start clean.service as it gives error all the time.
Last edited by archifer (2019-12-10 17:41:00)
Offline
What do you think ~ expands to when the script is executed by the service?
Offline
What do you think ~ expands to when the script is executed by the service?
I have replaced it to `rmlint /home/admin/`(instead) but it still won't do. It is weird because first time I created it, it was active process but after reboot I cannot start it anymore.
Offline
What is the contents of the script now and what is the service's status?
Have you also removed all the superfluous sudo usage?
Last edited by loqs (2019-12-10 17:55:40)
Offline
What is the contents of the script now and what is the service's status?
Have you also removed all the superfluous sudo usage?
Changed it like this
#!/bin/bash
# Trash cleaning script by archifer
yes Y | pacman -Sc
paccache -r
journalctl --vacuum-size=50
rmlint /home/admin/ && yes | sh /home/admin/rmlint.sh
rm -r /home/admin/.cache/*
pacman -Qtdq && pacman -R $(pacman -Qtdq)and if I run `systemctl start clean.service`
clean.service - Clean-up old pkgs and lint
Loaded: loaded (/etc/systemd/system/clean.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2019-12-10 20:01:57 EET; 1min 36s ago
TriggeredBy: ● clean.timer
Process: 19720 ExecStart=/home/admin/clean.sh (code=exited, status=1/FAILURE)
Main PID: 19720 (code=exited, status=1/FAILURE)Last edited by archifer (2019-12-10 18:08:37)
Offline
Ok it works now, thanks all for helping out, I used @Trilby suggestion to remove sudos and add `pacman -R $(pacman -Qtdq) || true` other issue was that `rmlint` didn't update .sh in home directory but created separate file in root directory so I had to change the path.
#!/bin/bash
# Trash cleaning script by archifer
yes Y | pacman -Sc
paccache -r
journalctl --vacuum-size=50
rmlint /home/admin/ && yes | sh /rmlint.sh
rm -r /home/admin/.cache/*
pacman -R $(pacman -Qtdq) || trueOffline
I'm glad the script is working now, but ...
The idea was to launch these commands weekly
Then why have you set the service to run at boot rather than once a week?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I'm glad the script is working now, but ...
archifer wrote:The idea was to launch these commands weekly
Then why have you set the service to run at boot rather than once a week?
That was probably my mistake I understood the procedure somewhat different but now it's all cleared out.
Offline
Please remember to mark your thread [SOLVED] (edit the title of your first post).
Offline