All Questions
Tagged with shell-script sudo
134 questions
0
votes
0
answers
31
views
Wildcard not expanding. sudo to blame? [duplicate]
RHEL 8.
$ alias suip
alias suip='sudo -iu postgres'
If I specify the complete filename, the ls command works as expected:
suip ls ~postgres/logs/pgbackrest_2025-04-30_01:00:01_incr.log
/var/lib/...
12
votes
2
answers
5k
views
Check if current user can run sudo without requiring a password
I want to check if the current user running a BASH shell script has access to passwordless sudo or not. If they don't, I'd rather have the script exit rather than prompting them for a password.
0
votes
0
answers
106
views
keep sudo effective without password after update sudo package itself
I want to write an automation script in Bash that requires frequent use of the sudo command. To avoid entering my password repeatedly after the sudo timeout, I've tried the following:
#!/bin/bash
sudo ...
1
vote
0
answers
116
views
How to run this particular command when an user login?
Every time i login i have to run this 2 commands:
To be able to make caps2esc program work. But i want to automate this process
cd ~/Apps/caps2esc
sudo bash -c 'nice -n -20 ./caps2esc >caps2esc.log ...
0
votes
2
answers
169
views
Easiest way to safely get the equivalent of SUID on a shell script
I have a script in which I need to mount an overlay to give an OCI container access to a mounted read-only directory /nix/store as if it was writable.
I would like to have this script be runnable by ...
0
votes
0
answers
36
views
How to properly format the command argument for sudo? [duplicate]
I have a command that is similar to this minimal example:
$ sh -c 'echo "1=$1"' _ foo
1=foo
$
When I want to run it through sudo, it stops working:
$ sudo -i -u user -- sh -c 'echo "1=...
0
votes
2
answers
514
views
using sudo or setuid with script for apache webserver
I have a home webserver I muck around with, mainly for learning and testing. I use Apache2 on Debian Bullseye.
One of the things I have been playing around with is running Bash scripts from the ...
0
votes
1
answer
717
views
Get current user who is using sudo [duplicate]
So, let's say I have a shell script that's supposed to be run as root, but I want to execute commands using runuser as the user who is running sudo. I could do runuser -u tux echo penguin. However, ...
1
vote
2
answers
3k
views
Debian : how to use a sudo bash script without password at startup
I am on Debian 11 testing. It's a low-end computer intended for users with little computer experience and I want to keep it up to date with a script that do not prompt users for a password.
Following ...
-1
votes
2
answers
1k
views
Why 2>/dev/null isnt't working?
I want to ask the user for sudo password at the beggining of my script and then make a test if this password is correct before running the rest of the script.
So after searching a while, I got this ...
0
votes
0
answers
490
views
My shell script won't run automatically as root using the NOPASSWD argument inside the sudoers file [duplicate]
I want to know why my script won't run as root on Ubuntu 22.04. I want that it does it regardless of the user that executes it, without asking for any kind of authentication. This script should run ...
0
votes
2
answers
881
views
How to access an enviroment variable of `$SUDO_USER`'s within a shell script?
My $USER's $SHELL env variable is /bin/zsh
My root's $SHELL env variable is /bin/bash
I am running a Unix shell script as sudo. In this script, I need to check if $SHELL env variable of $SUDO_USER ...
1
vote
1
answer
101
views
POSIX-compliant elevation detection
I'm writing a script that should be as POSIX compliant as possible, so I'm avoiding bashims. It requires elevated permissions (root) for some parts, and prompts the user if necessary - which requires ...
7
votes
3
answers
7k
views
passwordless check to see if a user can use 'sudo'
I want to check if a user is able to use sudo - but without the need to write the password - for bash shell scripts purposes. I did some research and I found:
Sudo - is there a command to check if I ...
0
votes
2
answers
84
views
logger command reports I am a user even if running under sudo?
I have a line
logger Ok
in my script. When I run it from command line with either of
./myscript.sh
sudo ./myscript.sh
sudo bash ./myscript.sh
it writes in log
Oct 17 22:32:01 d40688 mysqlf: Ok
I.e. ...