Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-14-2024, 07:43 AM
|
#1
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Rep:
|
Linux Mint 21.3: Autorunning Scripts at Events
Please help me get educated. I don't need the scripts written for me or anything. What I want to know, is at events, how to run bash (or other shell) scripts. What is the minimum events?
* Startup, after everything else in System D (the equivelent of the old autoexec.bat in Windows 98)
* Shutdown, sometime in System D processes (the equivelent of shutdown script in GP in Windows 10)
* At logon, whether from terminal, or from GUI
* At logoff, whether from terminal, or from GUI
* At cinnamon logon (I think I know how to do this already)
* At cinnamon logoff
* Every hour, if the computer is on (I think anacron can do this)
* Every day, if the computer is on (I think anacron can do this)
Only the cinnamon scripts would have access to the GUI I'm sure, which is OK with me, but I DO need those to have access to it.
These are the minmimum events and I'd say I should start with those, but do you guys also recommend other events (the second part of the question), and if so, what events. I'll only keep it open for so long, after I get the first part answered.
I do need very blank templates (you don't have to write the whole thing for me, but rather help me write them myself). Also, the commands to enable the scripts to run (They have to work in bash). Thanks in advance, and I bet it helps others too, especially if someone was to want a network of Linux Mint machines. I know 22 is almost out, but we'll work with what we got for now, for the question. I don't think I want to upgrade to 22, anyway, as it seems as if 22.1 would be a better time to upgrade. Thanks again, in advance!
|
|
|
07-14-2024, 08:56 AM
|
#2
|
Moderator
Registered: Aug 2002
Posts: 26,752
|
1. For startup there is systemd, rc.local and cron (@bootup).
2. For shutdown there is systemd.
3. For login there are shell login scripts as well as GUI auto start capability.
4. For logout there are shell logout scripts as well as running applications/scripts GUI post session but it depends on desktop and display manager.
5,6 Cinnamon is a desktop and therefore would not necessarily be separate from a GUI login/logout IMHO.
7. systemd or cron.
8. anacron can run scripts on a daily basis regardless of the exact time the computer is on.
9. Other events is mostly an open ended question because it depends.
|
|
|
07-14-2024, 09:12 AM
|
#3
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
That's a great start. Please slightly elaborate, if you can. I realize this may not be the spot for a "major" tutorial, but I need just a little bit more information to look stuff up. Over at Linux Cast discord, I've been told this is going to take some learning. I've been told I need to know about system d. I'm happy to learn more!
|
|
|
07-14-2024, 09:18 AM
|
#4
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
After coding some of these basic scripts, I'm going to be ready pretty much to officially support in my network, Linux Mint 21.3! I can update the scripts to work on later versions of Linux Mint. In fact, after some basic code has been written, it will become easy to update my scripts as network updates will be supported.
That's the first goal of my blank scripts being coded and filled in. As soon as I get a working solution, I will also share on github. Then, I can begin some work on other distributions with softi, and being able to work on servers again, after softi is updated for them. Thanks again!
|
|
|
07-14-2024, 04:46 PM
|
#5
|
Moderator
Registered: Aug 2002
Posts: 26,752
|
Quote:
Please slightly elaborate, if you can.
|
anacron, cron, bashrc, bashout_logout and rc.local should be fairly straight forward. You should be able to find lots of information. You can use systemd timers instead of cron or anacron. There are many options with systemd service files and how they are configured slightly depends on what type of script you are running.
https://www.digitalocean.com/communi...and-unit-files
|
|
|
07-16-2024, 12:41 AM
|
#6
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
Thanks! That's enough for additional research. I won't lose this thread, but I'll mark as solved, unless after deep reading, I still need help, but then it might fit better on a different thread.
|
|
|
07-22-2024, 11:30 PM
|
#7
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
Sorry to revive an older thread, but I thought it was most appropriate. I hooked "almost" all the events. The two remaining that I'm having trouble with, is some sort of general logoff script, and a cinnamon logoff script. If I could get the more general one working, I might be able to deal with not having a cinnamon logoff script working. I'm trying to do it currently with systemd. I now understnad some basics about systemd services. Enough that I've coded a basic shutdown script. I don't know yet whether for my roaming profile ambition, I will need logoff or shutdown for it to work. Honestly, all of this, about 10 years ago, with previous init solutions used to be a bit easier, though I was never ready to use it. Using the standard redhat init system at the time, as described in some very, very old books of mine. I used to insert it in a folder for the correct runlevel, with a shortuct, and it would work. That had some ease of use advantages. Here is current tries for the script proper:
Code:
#! /bin/bash
while :;
do
i=$(who | grep -c $(whoami))
if [ $i -eq 1 ]; then
bash /etc/settings/startup_scripts/logoffall2.sh
exit 0
fi
done
I tried hooking that at startup, but then it will never allow me to logon properly, and I barely got logged on another way to fix the issue.
systemd service:
Code:
SMILEY\des@e-des:/etc/systemd/system$ cat logoffall.service
[Unit]
Description=Logoff All Users Service
After=display-manager.service
[Service]
Type=oneshot
ExecStart=bash /etc/settings/startup_scripts/logoffall.sh &
RemainAfterExit=true
|
|
|
07-22-2024, 11:31 PM
|
#8
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
Oops! Sorry for the prompt in the second file. LOL!
|
|
|
07-23-2024, 05:15 AM
|
#9
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
Now I know everthing but the systemd one I'm trying to catch for logoff.
|
|
|
07-23-2024, 08:37 AM
|
#10
|
Moderator
Registered: Aug 2002
Posts: 26,752
|
Something like this should work.
Code:
[Unit]
Description=Logoff All Users Service
[Service]
Type=oneshot
RemainAfterExit=true
StandardOutput=journal
ExecStop=bash /etc/settings/startup_scripts/logoffall.sh
[Install]
WantedBy=default.target
Code:
while :;
do
i=$(who | grep -c $(whoami))
if [ $i -eq 1 ]; then
bash /etc/settings/startup_scripts/logoffall2.sh
exit 0
fi
done
If i is not 1 the script runs in an infinite loop. I do not see a point in testing for whoami.
|
|
|
07-23-2024, 11:18 PM
|
#11
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
I was wrong about the bash script working. Here is all the fixed versions:
logoffall.service
Code:
[Unit]
Description=Logoff All Users Service
[Service]
Type=oneshot
ExecStop=bash /etc/settings/startup_scripts/logoffall.sh
RemainAfterExit=true
StandardOutput=file:/etc/settings/startup_scripts/output.log
[Install]
WantedBy=default.target
logofall.sh
Code:
#! /bin/bash
while :;
do
if test $(who | grep -c -) == "0"; then
bash /etc/settings/startup_scripts/logoffall2.sh
exit 0
fi
done
|
|
|
07-23-2024, 11:21 PM
|
#12
|
Senior Member
Registered: Sep 2006
Posts: 1,572
Original Poster
Rep:
|
I had help elsewhere creating it, and boy, were they wrong about what works! Well, with their help, I still managed to fix the problem. Thanks for yours too. I won't keep it open longer, because I know how to create my last scripts. However, then I need to go back and remember how I did each one, so I can save them for later.
|
|
|
All times are GMT -5. The time now is 07:38 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|