LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 07-14-2024, 07:43 AM   #1
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572
Blog Entries: 45

Rep: Reputation: 39
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!
 
Old 07-14-2024, 08:56 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,752

Rep: Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318
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.
 
Old 07-14-2024, 09:12 AM   #3
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
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!
 
Old 07-14-2024, 09:18 AM   #4
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
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!
 
Old 07-14-2024, 04:46 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,752

Rep: Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318
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
 
Old 07-16-2024, 12:41 AM   #6
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
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.
 
Old 07-22-2024, 11:30 PM   #7
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
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
 
Old 07-22-2024, 11:31 PM   #8
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
Oops! Sorry for the prompt in the second file. LOL!
 
Old 07-23-2024, 05:15 AM   #9
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
Now I know everthing but the systemd one I'm trying to catch for logoff.
 
Old 07-23-2024, 08:37 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,752

Rep: Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318Reputation: 6318
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.
 
Old 07-23-2024, 11:18 PM   #11
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
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
 
Old 07-23-2024, 11:21 PM   #12
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,572

Original Poster
Blog Entries: 45

Rep: Reputation: 39
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error autorunning software - cannot find the autorun program ! ! ! ? ? ? Ti Malice Linux - Newbie 3 05-08-2009 10:33 AM
autorunning modules in fedora 7 moracca Fedora 6 08-12-2007 12:23 PM
Create an autorunning CD indraveni Debian 10 06-07-2006 03:46 PM
How to create an autorunning CD indraveni Linux - Software 1 06-05-2006 12:26 AM
Automounting, autoloading, autorunning... Thymox Linux - General 2 01-11-2002 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 07:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration