, to srat my shell script with sudo permission automatically with giving password using echo.
It works perfectly when I executed it by clicking mouse or using terminal.
And I wanted to execute it automatically when my device starts boot.
So I added it to systemctl service like; //MyService.service
[Unit]
Description=Auto Start
[Service]
ExecStart=/home/user/MyProgram/Myprogram_Start.sh
[Install]
WantedBy=default.tar get
, to ~/.config/systemd/user/
directory.
And I used $ systemctl --user enable MyService.service
to add it to my user systemctl service for autostart.
But it didnât work with this fail message by checking journalctl ;
pam_unix(sudo:session): session closed for user root
Myservice.service: Main process exited, code=exited, status=134/n/a
Myservice.service: Failed with result âexit-codeâ .
However, when I added my Myprogram_Start.sh to lxqt session settings - auto start - LXQT session,
it auto starts properly !
But it doesnât work well when I added it to global session like I added it to the service.
You typed something wrong (e.g. your default.tar get above)
Thereâs maybe an error because there are cached credentials. If you sudo something, you need to enter your password. However, if you do it again right away, you donât need to because of these cached credentials. I couldnât reproduce this behavior, but itâs a possibility. You can use the -k switch to invalidate cached credentials.
Thereâs something about the ultimate script (Myprogram.sh) youâre running thatâs to blame.
What I can tell you is that status=134/n/a is the exit code. So you should check the exit codes for whatever command is being run. The difficulty will be figuring out which command it is if thereâs a lot. To explain this consider this script:
So what happens here is that three exit codes are returned (5, 11, and 155, in that order), and then thereâs the echo at the end. So what do you think the exit code will be? You might think 5, 11, or 155, but itâs 0, because that very last command successfully exits.
So consider the case where we change the second function to foo2 () { exit 11; }. If we were to make that change and re-run it again, what will happen? Well, there wonât be an echo. foo3 () will never run. And the ultimate exit code? 11.
Hopefully thatâs enough information for you to figure this out yourself.
I corrected my service to WantedBy=default.target.
Funny thing is that it goes the same.
But when I registered it to LXQT session settings - Auto Start - LXQT session,
it works !