You are not logged in.

#1 2025-01-06 07:46:46

morphiuss
Member
Registered: 2025-01-06
Posts: 2

Executing script with scheduling systemd timer doesn't work

I've created three files:
1) ~/scripts/randomize_mac.sh

#!/bin/bash

# Change to your wireless interface
INTERFACE="wlan0"

# Generate a random MAC address
NEW_MAC=$(printf '%02x:%02x:%02x:%02x:%02x:%02x\n' $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)))

# Bring the interface down
sudo ip link set dev $INTERFACE down

# Change the MAC address
sudo ip link set dev $INTERFACE address $NEW_MAC

# Bring the interface back up
sudo ip link set dev $INTERFACE up

and made it executable

2) /etc/systemd/system/randomize-mac.service

[Unit]
Description=Randomize MAC Address

[Service]
Type=oneshot
ExecStart=/bin/bash /home/morphiuss/scripts/randomize_mac.sh

3) /etc/systemd/system/randomize-mac.timer

[Unit]
Description=Run Randomize MAC Address

[Timer]
OnBootSec=1min
OnUnitActiveSec=3min
Unit=randomize-mac.service

[Install]
WantedBy=timers.target

Then tried to start it with:
sudo systemctl start randomize-mac.timer

But after three minutes it didn't change my MAC.
I checked the status of the services and it seems like they worked(active at needed times).

What did I do wrong?

Offline

#2 2025-01-06 09:09:54

mithrial
Member
Registered: 2017-03-05
Posts: 151

Re: Executing script with scheduling systemd timer doesn't work

What does the journal show at time of execution?

Offline

#3 2025-01-06 13:44:26

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,194

Re: Executing script with scheduling systemd timer doesn't work

Is the script execute-/readable for "others"? Since you're passing a file in your home dir to a root ran service (you probably want to place that thing in a more global location in general).

Online

#4 2025-01-06 14:22:50

morphiuss
Member
Registered: 2025-01-06
Posts: 2

Re: Executing script with scheduling systemd timer doesn't work

Yes, forgot to mention that I run chmod +x on the script.
And thanks for reminding me about journal. I'm very new to all of these things.

I was finally able to detect that it's my MAC address validity that was causing the issue.

Offline

#5 2025-01-06 14:48:10

jl2
Member
From: 47° 18' N 8° 34' E
Registered: 2022-06-01
Posts: 1,339

Re: Executing script with scheduling systemd timer doesn't work

ExecStart=/bin/bash /home/morphiuss/scripts/randomize_mac.sh => ExecStart=/home/morphiuss/scripts/randomize_mac.sh (your already calling bash in the first line)

please prepend a [SOLVED] to your original post titel by editing it if it is solved.

Last edited by jl2 (2025-01-06 14:48:19)


Why I run Arch? To "BTW I run Arch" the guy one grade younger.
And to let my siblings and cousins laugh at Arsch Linux...

Upload longer text output like this

Offline

Board footer

Powered by FluxBB