Skip Navigation

User banner
Linux Troubleshooting and scripts

Members
0
Posts
18
Created
3 yr. ago

this is a community for sharing your scripts that help when working with Linux as well a general troubleshooting.

Rules

  • Absolutely NO NSFW posts. break this rule and you will be removed from this community. NO EXCEPTIONS!
  • Only post scripts that help yourself and others. All scripts will be tested on my machine personally, any malicious scripts will be removed immediately.
  • This community is for the benefit of other Linux users. no bigotry, hate, nudes, malicious scripts or politics allowed.

Feel free to ask any kind of support questions, as we grow more succinct answers will be available. Let's make this community grow.

We are important to one another, not only in the linux world but also in the fediverse as a whole. Feel free to reach out to me with questions or concerns, as we grow bigger I will look into adding mods. (This section will be updated as needed.)

🌉 bridged from !linuxscripts@lemmy.zip by Tidepool

Happy New Year Everyone

Just want to wish everyone a safe and happy new year. If you go out partying/drinking tonight, play it safe and use a cab to get home. Cheaper all around, no tickets to pay for DUI, no insurance increases because of a car wreck and no concern of how to replace your car if you get in one and last but not least, Your family gets to keep you around a little longer if you don't drive home drunk.

Happy New Year and see y'all in 2025

Quick oneliner ffmpg help

So, I was doing this: ffmpeg -i /media/johann/5461-000B/DCIM/100MEDIA/IMAG0079.AVI -ss 00:00:00 -t 00:00:20 ~/Public/240321/240321_0079.avi ; rm /media/johann/5461-000B/DCIM/100MEDIA/IMAG0079.AVI one at a time changing the IMAG0079 to IMAG0080 etc every time. I am sure there must be a way to perform two actions (ffmpg) and (rm) on each file in a folder. Can anyone help (For next time) Thanks!

Basic Lemmy API login script

 
#!/bin/bash

# Basic login script for Lemmy API

# CHANGE THESE VALUES
my_instance=""			# e.g. https://feddit.nl
my_username=""			# e.g. freamon
my_password=""			# e.g. hunter2

########################################################

# Lemmy API version
API="api/v3"

########################################################

# Turn off history substitution (avoid errors with ! usage)
set +H

########################################################

# Login
login() {
	end_point="user/login"
	json_data="{\"username_or_email\":\"$my_username\",\"password\":\"$my_password\"}"

	url="$my_instance/$API/$end_point"

	curl -H "Content-Type: application/json" -d "$json_data" "$url"
}

login

# Make note of "jwt" from reply

This'll reply with JSON data, that includes a value for "jwt", to be used in other scripts that require you to be logged in. Personally, I'd use the 'jq' program to de-serialize the JSON data, but I thought I'd keep the script simple for now

Welcome Everyone

Welcome to Linux Troubleshooting and Scripts. This community is for providing scripts that help with installing or maintaining Linux computers, primarily Home computers with desktop Linux. You can also post scripts or ask for support on home servers. this is a community for sharing your scripts that help when working with Linux as well a general troubleshooting. Rules • Absolutely NO NSFW posts. break this rule and you will be removed from this community. NO EXCEPTIONS! • Only post scripts that help yourself and others. All scripts will be tested on my machine personally, any malicious scripts will be removed immediately. • This community is for the benefit of other Linux users. no bigotry, hate, nudes, malicious scripts or politics allowed. Feel free to ask any kind of support questions, as we grow more succinct answers will be available. Let’s make this community grow. We are important to one another, not only in the Linux world but also in the Fediverse as a whole. Feel free to reach out to me with questions or concerns, as we grow bigger I will look into adding mods. (This section will be updated as needed.)

Engagement with community

Hey everyone, just wanted to touch base with y’all. I’m really a little worried about our community.

As of this writing we have 295 members, but we only have 11 posts, including this one. We really need to get some quality posting going on here.

So this is what I was thinking, let’s start a mega thread of conversations around Linux in general. I would like to see what we can get going here. Also please talk to your friends that are on here and invite them to the group.

I know a lot of us, myself included, tend to just lurk until something pops up for us to interact with. I’m asking everyone here to help interact with our community. We aren’t just a help desk here, we can also have fun conversations.

Import Windows EFI in Linux systemd-boot

If you have a dual boot setup like mine and want to utilize Linux systemd-boot for managing the Windows dual boot, I've put together a concise guide for myself, which may also be of interest to a few people. Here are the steps you can follow: 1. Find the partition of the Windows EFI system with lsblk. (The partition must be around 100Mo)

 
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 465,8G  0 disk
├─sda1        8:1    0   100M  0 part
├─sda2        8:2    0    16M  0 part
├─sda3        8:3    0   465G  0 part
└─sda4        8:4    0   639M  0 part
zram0       254:0    0     4G  0 disk [SWAP]
nvme0n1     259:0    0 931,5G  0 disk
├─nvme0n1p1 259:1    0   511M  0 part /boot
└─nvme0n1p2 259:2    0   931G  0 part /var/log
                                      /var/cache/pacman/pkg
                                      /home
                                      /.snapshots
                                      /

3. Mount this partition with sudo mkdir /mnt/windows-boot && sudo mount /dev/sda1 /mnt/windows-boot. (In this example sda1 is the partition needed) 4. Copy the needed directory to boot folder with sudo cp -r /mnt/windows-boot/EFI/Microsoft /boot/EFI/Microsoft. 5. Create the needed entrie config file

 
su -
cd /boot/loader/entries
touch windows.conf

and put this code inside :

 conf
title Windows 11
efi /EFI/Microsoft/Boot/bootmgfw.efi

5. Reboot This guide is specifically tailored for an Arch Linux installation, but it can be easily adapted to suit other Linux distributions. Please note that the steps provided in this guide are primarily focused on configuring dual boot using Linux systemd-boot. While the overall process may be similar across various distributions, there might be slight variations in specific commands or file paths. Therefore, it's recommended to consult your distribution's documentation or community resources for any distro-specific instructions.

Basic Lemmy API "get unread replies" script

Run the "Basic Lemmy API login script" (see here) first to get value for 'jwt'

 
#!/bin/bash

# Basic get unread replies script for Lemmy API

# CHANGE THESE VALUES
my_instance=""			# e.g. https://feddit.nl
my_username=""			# e.g. freamon
my_password=""			# e.g. hunter2

jwt=""			# run basic login script to get this

########################################################

# Lemmy API version
API="api/v3"

########################################################

# Turn off history substitution (avoid errors with ! usage)
set +H

########################################################

# Get inbox messages
get_unread_replies() {
	end_point="user/replies"
	www_data="auth=$jwt&unread_only=true"

	url="$my_instance/$API/$end_point?$www_data"

	curl "$url"
}

get_unread_replies

Personally, I'd use the 'jq' program to de-serialize the reply, e.g.

get_unread_replies.sh | jq '.replies[].comment.content'

My next plan is to use a script like this with a notification service like PUSHOVER, so it can ding my phone if I've an unread message For each API method, whether it's GET or POST and end_point can be found here, and then each method has a click-through to see what parameters it can take.

Please help the community grow by posting

Hi all, I really appreciate the number of member we have here at linuxscripts, and we have had a few posts besides my own on here.

What I would really like is for some of you to post things if you have them, and of course let others know about our existence.

You don’t have to post content to o be a member here, but please help contribute in any manner you can. I am opening the community up to more content today allowing for memes and crossposts of news surrounding Linux. If you cross post please denote that in your post so others know. I do ask that you don’t cross post unsolved help posts unless it is your own. However, if you get a solution to your problem and it’s not on here please let me know so it can be locked.

Thanks everyone.

Switching bluetooth keyboards force mutes all devices

Hi, I am new to linux and started off with Nobara KDE, updated to latest and facing a problem with my new bluetooth keyboard. It can store upto 3 devices and can switch between them. Whenever I switch out of the system to my work laptop it force mutes all playback device without interfering with media and I have to toggle it back on manually. I have pulse audio and but I believe only pipewire-pulse is running under process. I am adding some screen shots with imgur hoping that would help. Would appreciate some help or hints on how this cant be fixed. Thanks.

imgur.com

a python script for servers

This is a database script i made to trigger when database events trigger a database lockup.

 
# Make sure to change your database info and what instance of DB you are using (i.e. sqlite3, mysql, postgres etc...)
# This script will rotate for a total of 5 logs so you can compare previous errors with current one without taking unnecessary space

# There's no strict requirement to place it in the root directory of the server, but you have some options for where to put it:

# Root Directory: Placing the script in the root directory could work, but it's generally not recommended to clutter the root directory
# with scripts. It's better to create a specific directory for your application and put the script there.

# Custom Directory: Create a specific directory for your application, and place the script there. 
# For example, you could create a directory called "my_app" or "database_error_logger" and place the script in that directory.

# Scripts Directory: Some servers have a designated directory for executable scripts. 
# You might check if your server has a "scripts" directory where you can place your script.

# Regardless of the location, it's essential to consider file permissions. 
# Ensure that the script has the necessary permissions to execute. You may need to use the chmod command to set the appropriate 
# permissions, depending on your server's configuration.

# Lastly, consider setting up a virtual environment for your Python script to isolate dependencies and avoid conflicts with other 
# applications on the server. This can help ensure that the required Python libraries are installed locally for your script
# without interfering with system-wide packages.    

# This script was created by Edward Freeman and is covered under GPL V3. You can modify this script as you need
# However, you must retain this GPL V3 standard, and leave credit where credit is due to the original author.

import logging
from logging.handlers import RotatingFileHandler
import sqlite3 #Make sure you change this to the correct Database provider (sqlite3, mysql, postgres etc..)
import sys

# Configure logging with rotating file handler
log_file = 'database_errors.log'
log_handler = RotatingFileHandler(log_file, maxBytes=1024 * 1024, backupCount=5)
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s')
log_handler.setFormatter(log_formatter)
logger = logging.getLogger('DatabaseErrorLogger')
logger.setLevel(logging.ERROR)
logger.addHandler(log_handler)

def perform_database_operation():
    try:
        # Replace the following line with your actual database connection and query
        connection = sqlite3.connect('your_database.db')
        cursor = connection.cursor()

        # Replace the following line with your actual database operation
        cursor.execute('SELECT * FROM your_table;')

        # Don't forget to commit the changes if you are performing write operations
        connection.commit()

        connection.close()
    except Exception as e:
        # Log the error with the traceback using the logger
        logger.exception("Error occurred while performing the database operation.")
        raise  # Raising the error again allows the script to terminate or handle it at a higher level if needed

def custom_exception_handler(exctype, value, traceback):
    # Log uncaught exceptions using the logger
    logger.exception("Uncaught exception occurred.", exc_info=(exctype, value, traceback))

# Set the custom exception handler for uncaught exceptions
sys.excepthook = custom_exception_handler

# Call the function to perform the database operation
try:
    perform_database_operation()
except Exception as e:
    print("Error occurred during the database operation:", str(e))