Cant disable WiFi power management Raspberry Pi 3 - raspberry-pi3

Whenever i access sudo nano /etc/network/interfaces the file is essentially empty which is hindering me because i need to disable the power saving feature that automatically disables the wifi after a minute or so
This is what shows in my file
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
Because of this there is no where i can add the wireless-power off text and have it work.I have already tried to add this just at the bottom but it does not work.

Firstly you should repost this over at https://raspberrypi.stackexchange.com/
Secondly I am just facing the same issue, and solved it by entering this line into the crontab:
#reboot /sbin/iw dev wlan0 set power_save off&

I used the below to PERSISTENTLY kill WiFi Power Management across reboots. It's done as a systemd service so independent of how the network interfaces are configured and "just works".
Should work on any modern Pi which has systemd. Just copy & paste below bash script into a file, set it to executable and sudo ./fileName.sh:
if [ -d /root/scripts ]; then
mkdir /root/scripts
fi
apt-get -y install iw
apt-get -y install wireless-tools
cat <<EOF> /root/scripts/pwr-mgmnt-wifi-disable.sh
#!/bin/bash
iw dev wlan0 set power_save off
EOF
chmod 700 /root/scripts/pwr-mgmnt-wifi-disable.sh
cat <<EOF> /etc/systemd/system//pwr-mgmnt-wifi-disable.service
[Unit]
Description=Disable WiFi Power Management
Requires=network-online.target
After=hostapd.service
[Service]
User=root
Group=root
Type=oneshot
ExecStart=/root/scripts/pwr-mgmnt-wifi-disable.sh
[Install]
WantedBy=multi-user.target
EOF
chmod 644 /etc/systemd/system/pwr-mgmnt-wifi-disable.service
systemctl enable pwr-mgmnt-wifi-disable.service
systemctl start pwr-mgmnt-wifi-disable.service

Related

RaspberryPi - error when trying to reference a user directory on boot service?

I am trying to reference a user directory on boot for my raspberry pi 4 32 bit bullseye desktop with a service setup on systemctl. This service maps my ip address to an .env file. The process is as follows:
setup.service attempts to create a .env file using setup.sh with my current ip address
setup.timer fires off the service 1 minute after boot
This works flawlessly when my setup.sh looks like this:
...
destdir=/home/me/my_directory/.env
echo "REACT_APP_MACHINE_HOST_IP=$REACT_APP_MACHINE_HOST_IP" > "$destdir"
But when I try to replace the value of "me" with the machine user in order to make this more transferrable I get this error on boot:
...
destdir=/home/"$USER"/my_directory/.env
echo "REACT_APP_MACHINE_HOST_IP=$REACT_APP_MACHINE_HOST_IP" > "$destdir"
/home//my_directory/.env does not exist...
Not sure where I'm off because I made a quick test.sh script and the following echoed the directory correctly:
#!/bin/bash
mydir=/home/"$USER"/my_directory/
echo $mydir
It seems like no user is recognized. I am assuming this has something to do with system running on root? Or is my syntax off?
EDIT:
My setup.service below:
[Unit]
Description=setup mcw
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/setup.sh
[Install]
WantedBy=multi-user.target
And what I run to automate aka automate.sh:
# copy ip file to task and authorize
sudo cp /home/${USER}/my_directory/setup.sh /usr/local/bin/setup.sh
sudo chmod 744 /usr/local/bin/setup.sh
# create setup files
sudo cp /home/${USER}/my_directory/setup.service /etc/systemd/system/setup.service
sudo cp /home/${USER}/my_directory/setup.timer /etc/systemd/system/setup.timer
# add permissions for the service
sudo chmod 644 /etc/systemd/system/setup.service
# setup and reload systemctl
sudo systemctl daemon-reload
sudo systemctl enable setup.timer
sudo systemctl start setup.timer

Prevent .bash_profile from executing when connecting via SSH

I have several servers running Ubuntu 18.04.3 LTS. Although it's considered bad practice to auto login, I understand the risks.
I've done the following to auto-login the user:
sudo mkdir /etc/systemd/system/getty#tty1.service.d
sudo nano /etc/systemd/system/getty#tty1.service.d/override.conf
Then I add the following to the file:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin my_user %I $TERM
Type=idle
Then, I edit the following file for the user to be able to automatically start a program:
sudo nano /home/my_user/.bash_profile
# Add this to the file:
cd /home/my_user/my_program
sudo ./program
This works great on the console when the server starts, however, when I SSH into the server, the same program is started and I don't want that.
The simplest solution is to SSH with a different user but is there a way to prevent the program from running when I SSH in using the same user?
The easy approach is to check the environment for variables ssh sets; there are several.
# only run my_program on login if not connecting via ssh
if [ -z "$SSH_CLIENT" ]; then
cd /home/my_user/my_program && sudo ./program
fi

/etc/rc.local is missing from my headless ubuntu 18.04

I am currently hosting a minecraft server on ubuntu server 18.04 LTS. I have a .sh script to start the server's java file, and I would like to run it at startup so that the minecraft server starts when the physical server boots. I wished to do this via /etc/rc.local. However, I do not see rc.local in that location.
Is it in a different location for this version of ubuntu, or is there an entirely different method I should use to run this .sh at startup?
There is no "/etc/rc.local" file on Ubuntu 18.04, but you can create it.
Create the file with a text editor:
sudo nano /etc/rc.local
Paste the following lines and replace "COMMANDS" with the commands to be executed at system startup:
#!/bin/sh -e
COMMANDS
exit 0
Add the execute permission on the file:
chmod +x /etc/rc.local
Set a crontab for this
Make sure the file is executable:
chmod +x /path_to_you_file/your_file/file.sh
To edit crontab file:
crontab -e
Then add this:
#reboot /path_to_you_file/your_file/file.sh
rc.local is disabled by default.
Enable by using this command
sudo systemctl enable rc-local.service

Files in docker container disappear

I am working on creating a backup script for some Docker contains. Some really strange thing happens when I copy files from a dir inside a Docker container to a host mounted dir - The files disappear.
EDIT: I managed to simplify the example and isolate the strange phenomenon:
#!/usr/bin/env bash
docker run -it --name gen_skeleton_cont \
mailman_server \
ls /etc && \
echo "Second ls:" && \
ls /etc \
# Cleanup the gen_skeleton_cont:
docker rm -f gen_skeleton_cont
The output of running this script is:
$ sudo bash check_incon.sh
Muttrc bash.bashrc cron.monthly environment hosts.allow issue.net logcheck mke2fs.conf os-release python rc6.d services sudoers ufw
Muttrc.d bash_completion.d cron.weekly fstab hosts.deny kbd login.defs modprobe.d pam.conf python2.7 rcS.d sgml sudoers.d update-motd.d
X11 bindresvport.blacklist crontab fstab.d init kernel logrotate.conf modules pam.d python3 resolv.conf shadow supervisor upstart-xsessions
adduser.conf blkid.conf dbus-1 gai.conf init.d ld.so.cache logrotate.d mtab passwd python3.4 resolvconf shadow- sysctl.conf vim
aliases blkid.tab debconf.conf group initramfs-tools ld.so.conf lsb-release network passwd- rc.local rmt shells sysctl.d vtrgb
aliases.db ca-certificates debian_version group- inputrc ld.so.conf.d magic networks perl rc0.d rpc skel syslog-ng wgetrc
alternatives ca-certificates.conf default gshadow insserv ldap magic.mime newt postfix rc1.d rsyslog.conf ssl systemd xml
apache2 console-setup deluser.conf gshadow- insserv.conf legal mailcap nologin ppp rc2.d rsyslog.d subgid terminfo
apparmor cron.d depmod.d host.conf insserv.conf.d libaudit.conf mailcap.order nsswitch.conf profile rc3.d securetty subgid- timezone
apparmor.d cron.daily dhcp hostname iproute2 locale.alias mailman ntp.conf profile.d rc4.d security subuid ucf.conf
apt cron.hourly dpkg hosts issue localtime mime.types opt protocols rc5.d selinux subuid- udev
Second ls:
acpi ca-certificates.conf dhcp host.conf kbd lsb-release opt python3.4 screenrc sudoers w3m
adduser.conf calendar digitalocean hostname kernel ltrace.conf os-release rc0.d securetty sudoers.d wgetrc
alternatives chatscripts dpkg hosts kernel-img.conf magic pam.conf rc1.d security sysctl.conf wireshark
apm cloud environment hosts.allow landscape magic.mime pam.d rc2.d selinux sysctl.d wpa_supplicant
apparmor console-setup fish hosts.deny ldap mailcap passwd rc3.d services systemd X11
apparmor.d cron.d fonts ifplugd ld.so.cache mailcap.order passwd- rc4.d sgml terminfo xml
apport cron.daily fstab init ld.so.conf manpath.config perl rc5.d shadow timezone zsh_command_not_found
apt cron.hourly fstab.d init.d ld.so.conf.d mime.types pm rc6.d shadow- ucf.conf
at.deny cron.monthly fuse.conf initramfs-tools legal mke2fs.conf polkit-1 rc.digitalocean shells udev
bash.bashrc crontab gai.conf inputrc libaudit.conf modprobe.d popularity-contest.conf rc.local skel ufw
bash_completion cron.weekly groff insserv libnl-3 modules ppp rcS.d smi.conf updatedb.conf
bash_completion.d dbus-1 group insserv.conf locale.alias mtab profile resolvconf ssh update-manager
bindresvport.blacklist debconf.conf group- insserv.conf.d localtime nanorc profile.d resolv.conf ssl update-motd.d
blkid.conf debian_version grub.d iproute2 logcheck network protocols rmt subgid update-notifier
blkid.tab default gshadow iscsi login.defs networks python rpc subgid- upstart-xsessions
byobu deluser.conf gshadow- issue logrotate.conf newt python2.7 rsyslog.conf subuid vim
ca-certificates depmod.d hdparm.conf issue.net logrotate.d nsswitch.conf python3 rsyslog.d subuid- vtrgb
gen_skeleton_cont
As can be seen, the two invocations of ls give different results. Maybe the container hasn't finished loading? I must be missing something.
If it helps, the full repository is here (Including Docker files):
https://github.com/realcr/mailman_docker
I think I found the problem. It is not related to Docker at all. It's a bash thing.
When invoking:
docker run -it --name gen_skeleton_cont \
mailman_server \
ls /etc && \
echo "Second ls:" && \
ls /etc \
The first ls happens inside the Docker container, however the second one happens inside the host machine. I should find some other way to run multiple commands inside a Docker container, maybe using another .sh file.

Transmission will not run shell script after torrent download completed

I am looking to have the Transmission bittorrent client execute a script that changes the owner and permissions of all torrents in the completed folder when a torrent completes downloading.
I am using the following relevant settings in /etc/transmission-daemon/settings.json:
"download-dir": "/data/transmission/completed",
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/home/user/script.sh",
The script does not seem to be executing after a torrent completes, I know there are other issues that could be going on aside the from the content of the script itself. The owner of the script file is debian-transmission and I have the permissions set to 777, so there shouldn't be an issues with Transmission accessing the script unless I have missed something here.
The /home/user/script.sh file is as follows:
#!/bin/bash
echo sudopassword | /usr/bin/sudo -S /bin/chmod -f -R 777 /data/transmission/completed
echo sudopassword | /usr/bin/sudo -S /bin/chown -f -R user /data/transmission/completed
I know it is poor form to use a sudo command in this fashion, but I can execute the script on it's own and it will work correctly. I am not sure why Transmission is not executing the script. Transmission supports some environment variables such as TR_TORRENT_NAME that I would like to use once the script is being triggered. Is there anything I am not setting up in the file that would prevent the script from working correctly and how would I use environment variables?
I'll probably answer a different question here, but if you're trying this simply to gain write permissions on your Transmission Daemon's downloads to your user, try a different approach.
I'm running my Transmission Daemon under my username, as set in it's systemd service file. (/etc/systemd/system/multi-user.target.wants/transmission-daemon.service in my case)
[Unit]
Description=Transmission BitTorrent Daemon
After=network.target
[Service]
User=myuser # set user here
Group=mygroup # set group here :)
UMask=0022 # 0022 gives 644 permissions on files (u+w), 0002 gives 644 (g+w), 0000 gives 666 (a+w)
Type=notify
ExecStart=/usr/bin/transmission-daemon -f --log-error
ExecStop=/bin/kill -s STOP $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
[Install]
WantedBy=multi-user.target
Notice User, Group and UMask (with capital M) directives.
See Execution environment configuration for Systemd manpage.
Then run:
sudo chown -fR user /data/transmission/completed
sudo systemctl daemon-reload
sudo service transmission-daemon restart
and you should set :)
Add the user who will execute the script to a group with default sudo access.
Fedora - add user to the wheel group
sudo usermod -aG wheel $(whoami)
Ubuntu - user group: sudo or admin (deprecated)

Resources