this post was submitted on 24 Dec 2024
263 points (96.1% liked)

Programmer Humor

19990 readers
1064 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
all 39 comments
sorted by: hot top controversial new old
[–] 01189998819991197253@infosec.pub 108 points 3 weeks ago (1 children)

I've found out the hard way: Running the script during startup, and running it using the proper user authorization, are two different things.

[–] qjkxbmwvz@startrek.website 53 points 3 weeks ago (2 children)

And environment


DISPLAY and PATH in particular.

[–] bleistift2@sopuli.xyz 32 points 3 weeks ago

You’re right and I’m dumb. I forgot to absolute-ify one of the paths, which caused the script to be dependent on my user environment, which isn’t loaded by the desktop file.

[–] bleistift2@sopuli.xyz 21 points 3 weeks ago (1 children)

Knowing that the environment is finicky, I made sure to only use absolute paths to all files and executables.

But thanks for the hint.

[–] ogeist@lemmy.world 6 points 3 weeks ago (1 children)

What are you using as a Desktop Environment? Certain with DEs the Autostart programs need to be added in the config file.

[–] bleistift2@sopuli.xyz 5 points 3 weeks ago (1 children)

Cinnamon.

Which config file?

[–] ogeist@lemmy.world 2 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

According to the Arch Wiki you need to place the .desktop file in:

~/.config/autostart/*****.desktop

You also need to add the following line to the .desktop file:

X-GNOME-Autostart-enabled=true

But that's probably the hard way to do it, I think the settings panel should also have a Startup Application tab.

[–] bleistift2@sopuli.xyz 2 points 3 weeks ago (1 children)

Thanks for looking that up. That’s where my desktop file is located. And it has the X-GNOME-Autostart-enabled=true line. The settings panel does have a Startup Application tab, and that’s what I used. It created the .desktop file in the appropriate location.

[–] ogeist@lemmy.world 1 points 3 weeks ago (1 children)

surprised_pikachu_face.jpeg

Check your journald and/or make your script log it's actions.

Script > ~/script.log
[–] bleistift2@sopuli.xyz 3 points 3 weeks ago

Thank for your help. Upon looking at it again I noticed the one filepath that relied on my profile being loaded. Corrected that. Works now.

Trés stupide

[–] RoyaltyInTraining@lemmy.world 39 points 3 weeks ago (3 children)

Weird that it doesn't work. The usual way to run scripts on startup is through systemd units though. That has the added benefits of automatically logging all output and letting you control it through commands like systemctl enable <unit name>. It's a really neat system, and I highly recommend learning it if you see yourself doing this kind of automation more often.

[–] pearsaltchocolatebar@discuss.online 16 points 3 weeks ago (2 children)

You can also get cron to do it.

[–] valkyre09@lemmy.world 8 points 3 weeks ago (1 children)

I miss the days of just sticking it in /etc/rc.local

[–] felbane@lemmy.world 1 points 3 weeks ago

Hey everyone, get a load of this fool drinking from an I ♥️ SYSV mug! Ha!

hides Lennart Pottering dartboard while everybody's distracted

[–] MonkderVierte@lemmy.ml 1 points 3 weeks ago

The usual way to run scripts on startup is through systemd units though.

Even worse than via some utility of your window manager

[–] ulterno@programming.dev 1 points 3 weeks ago (1 children)

I do that when I want it running with root privileges.
In case of user privileges though, the autostart is a better idea.

[–] dbx12@programming.dev 2 points 3 weeks ago

You was m can use user units too if you want them scoped to your user.

[–] SnotFlickerman@lemmy.blahaj.zone 35 points 3 weeks ago* (last edited 3 weeks ago) (4 children)

When all else fails...

crontab -e

@reboot sleep 300 && sudo ./myshell.sh

(this is actually broken on some distros)

[–] Scoopta@programming.dev 21 points 3 weeks ago (2 children)

I've been in the systemd world so long none of my systems even have cron

[–] GravitySpoiled@lemmy.ml 24 points 3 weeks ago (1 children)

That sounds like a sad world. I like cron

[–] Scoopta@programming.dev 2 points 3 weeks ago

LOL, I actually like systemd timers, cron seems easier to setup quickly but I do like some of the features of timers combined with services.

[–] xmunk@sh.itjust.works 1 points 3 weeks ago

Reject systemd embrace bashrc.

[–] marcos@lemmy.world 4 points 3 weeks ago (1 children)

Though, not every cron supports that.

Also, if you are packaging software, you have to do it the right way. But if not, it's often easier to go and install an init script.

[–] SnotFlickerman@lemmy.blahaj.zone 3 points 3 weeks ago (1 children)

I actually edited my comment right as you were responding. It's definitely broken in some distros, I think debian/ubuntu.

[–] marcos@lemmy.world 3 points 3 weeks ago

It's not broken. You just have to get a cron that supports it. Debian has at least one that does, but it's not the default one.

[–] bleistift2@sopuli.xyz 3 points 3 weeks ago (1 children)
[–] SnotFlickerman@lemmy.blahaj.zone 13 points 3 weeks ago* (last edited 3 weeks ago)

Just to make sure it pops off after fully starting up. I run a lot of old hardware, so it's useful for me. You may not need a delay.

[–] bleistift2@sopuli.xyz 3 points 3 weeks ago

Thanks. man 5 crontab says the @reboot syntax is supported, so I’ll give that a try if I don’t stumble upon a different solution.

[–] boredsquirrel@slrpnk.net 15 points 3 weeks ago (1 children)

Never heard of a .application file

Normally you need a .desktop file

[–] bleistift2@sopuli.xyz 15 points 3 weeks ago* (last edited 3 weeks ago)

Indeed, I made this meme from memory and got the extension wrong.

I corrected the meme. Thanks for pointing out the error

[–] mindbleach@sh.itjust.works 7 points 3 weeks ago (1 children)

"Can you mount the /media/user/Backup drive on startup?"

"Sure."

"... where is it?"

"Somewhere else."

[–] swab148@lemm.ee 0 points 3 weeks ago (1 children)

Drop that sucka in /etc/fstab

[–] embed_me@programming.dev 2 points 3 weeks ago

If I remember correctly, when fstab is incorrect even if the partition is not essential it will stop you from booting

[–] majiks@lemm.ee 2 points 3 weeks ago (1 children)

gnome-terminal -- sh -c "my_command" This will open that command in new terminal window at login

[–] skulblaka@sh.itjust.works 2 points 3 weeks ago (3 children)

Hey, I was working on the same problem the other day and maybe you can help me with it a bit further. If you don't mind.

I like to run gotop on my second monitor so I can watch my system resources, and normally I just open a terminal window and type gotop and it runs and stays open and continually updates. I've made this command into a shell script to run at startup. Using this script presumably halfway works, because a terminal window shows up, but it tells me "the child process exited normally with status 127." and prompts for relaunch (which does nothing except present the same message again).

Now the internet tells me that 127 generally means "command not found" which doesn't really make sense to me because gotop is in my PATH and can be run normally without any kind of special arguments or location if I pop open a terminal and do it myself. So I'm not really sure where the problem lies. The script in question is currently parked on my desktop and when I run it manually, when logged in and everything, nothing changes except that I also get an additional terminal window that states the child process exited normally with status 0.

I'm brand new to both Linux and shell scripting so I barely have any idea what I'm doing here, I've gathered through individual research that I should also have a line starting the file with #! /bin/bash but I'm not actually even too confident about that part. Currently the entire script reads as follows:

#! /bin/bash gnome-terminal -- sh -c gotop

I've tried with and without quotes on gotop and I've tried with and without the hashbang and none of the four options have given me different results, which makes me think I'm barking at the wrong tree. I have made the script executable so I don't think that's the problem.

O wise one, please bestow upon the poor noob your knowledge. (This request is also open to other wise ones who may be passing by.)

[–] ABasilPlant@lemmy.world 3 points 3 weeks ago

I'm unsure whether your formatting messed up, but you shouldn't have a space between the shebang (#!) and the interpreter path (/bin/bash). Also add a new line before your command:

#!/bin/bash

gnome-terminal -- sh -c gotop

I tried this on my system (with htop instead of gotop) and it worked.

[–] Hawk@lemmynsfw.com 2 points 3 weeks ago

For debugging sake, put the full path to the binary, eg /usr/bin/gotop (check with which gotop)

[–] majiks@lemm.ee 2 points 3 weeks ago

Honestly, I have no idea :D. What I would try is:

1st check that the command is on 2nd line of script (1st line is only #!/bin/bash, note that there is no space) but that might seem wrong only due to lemmy formatting.

2nd I'd try using full path of gotop binary. Use which gotop to find where it is. Must start with a /

3rd I'd try w/o script at all. The command I quoted works in Cinnamon startup applications from the "start" menu, add new entry there with your command.

4th chatgpt knows a lot about common linux problems.