I'm connected to a Solaris 9 machine using a user1 account.
bash-2.05$ /usr/ucb/whoami
user1
When i run any command using nohup, it executes with root privileges:
bash-2.05$ nohup whoami &
[1] 20479
bash-2.05$ Sending output to nohup.out
[1]+ Done nohup whoami
bash-2.05$
bash-2.05$ cat nohup.out #actually we had to user root here to do `cat` as `nohup.out` belongs to root, but for demonstration i ommited this step
root
This behavior can be seen only for this particular account user1. For other accounts it's executed with the correct user.
Here's the attributes of nohup
bash-2.05$ which nohup
/usr/bin/nohup
bash-2.05$ ls -altr /usr/bin/nohup
-r-sr-xr-x 43 root bin 5424 Dec 5 2005 /usr/bin/nohup
Thank you
Related
I'm trying to redirect stdout and stdin from within a script, designed to be run by either root or a privileged user, to a directory (/var/log/backups/) which is owned by root, group syslog. It works fine when run as root, but not when run as a user belonging to group syslog.
$ grep syslog /etc/group
adm:x:4:syslog,ubuntu,me
syslog:x:108:me
$ ls -dl /var/log/backup
drwxrwxr-x 2 root syslog 4096 Jun 8 14:17 /var/log/backup
part of my script:
LOG_DIR="/var/log/backup/"
sudo_cmd=
user=`whoami`
if [ ${user} != "root" ]; then
sudo_cmd="sudo"
fi
echo "sudo_cmd: " ${sudo_cmd}
...
logfile=${LOG_DIR}${filnam}.log
${sudo_cmd} touch ${logfile}
${sudo_cmd} chgrp syslog ${logfile}
${sudo_cmd} chmod 664 ${logfile}
${sudo_cmd} exec >> ${logfile} 2>&1
Even when run outside of the script, the redirection fails when run as a not-root user with group write access:
$ ls -l $logfile
-rw-rw-r-- 1 root syslog 0 Jun 8 15:08 /var/log/backup/foo.log
$ ${sudo_cmd} exec >> ${logfile} 2>&1
sh: 13: cannot create /var/log/backup/foo.log: Permission denied
clues?
My PostgreSQL v10 is running on a UBUNTU server. The user group www-data contains the user postgres, as checked by grep ^www-data /etc/group. When I do sudo chown -R :postgres MyPath it works fine, but when I change to sudo chown -R :www-data MyPath it not works.
How to set permissions for postgres user access other user group?
NOTES
As #LaurenzAlbe suggested on comment, the ls -ld myPath is drwxrwxr-x 29 root postgres 4096 Feb 27 15:54 myPath
and id postgres is uid=112(postgres) gid=117(postgres) groups=117(postgres),33(www-data),116(ssl-cert)
Im writing a shell to automate a process this shell will be run as root or as another user but not as the postgres user (meaning the user will just run the script)
What i did as a postgres user while testing was
touch /var/lib/postgresql/10/main/recovery.conf
sudo nano recovery.conf (wrote some content )
ctrl +O
However whenever I try to do this by using the following lines in my shell as as another user (including root)
sudo -H -u postgres bash -c "touch /var/lib/postgresql/10/main/recovery.conf"
The file is created as postgres user which is what i intended, and then i run
sudo -H -u postgres bash -c echo "content" > /var/lib/postgresql/10/main/recovery.conf
and get a
-bash: /var/lib/postgresql/10/main/recovery.conf: Permission denied
How come I can create the file but not put content on it?
I already tried giving 775 and 777 permisions using chmod
chmod 775 recovery.conf
as the psotgres user and i get
-rwxrwxr-x 1 postgres postgres 133 May 11 22:11 recovery.conf
to this file as a postgres user and still the error persists so im confused about whats going on
At the second line where you try to put the "echo" command, please use:
/var/lib/postgresql/10/main/recovery.conf
With a / at the beginning
I see that this question has been posted and answered. However, the post answer does not work for me. The posted answer has 2 solutions:
1 - run bashdb as root
this does not work for me because the script I am trying to debug must be run as mqm. This script exits when it sees that it is being run (via bashdb) as root.
2 - Add the user to the group listed by ls -l $(tty)
I ran this command and got:
mqm#localhost.localdomain(/var/mqm/scripts): ls -l $(tty)
crw--w----. 1 root tty 136, 0 Jun 17 10:11 /dev/pts/0
I ran (as root) usermod -a -G root mqm
and verified that the root group contains mqm -
then logged in as mqm, I re-ran
bashdb myscript
and again received this error
/usr/share/bashdb/lib/setshow.sh: line 91: /dev/pts/0: Permission denied
Bashdb also has a --tty option.
By default, bashdb ... is the same as bashdb --tty $(tty). So try giving an explicit --tty argument with a name of a tty or psuedo tty that you know you can write to.
Here is how you might test having access to the tty before running bash. Suppose the tty is /dev/pts/2 then run
echo hi > /dev/pts/2
If that works, then try bashdb -tty /dev/pts/2 ...
I am trying to find a way to run a script on sleep before an x session ends, because the script requires an active x session to execute properly. Storing the script in /etc/pm/sleep.d did not work (and returned errors related to a non-existent x session). Any ideas where to put the script?
Update in response to comments
king#death-star /etc/acpi $ cat 01_revert_kb_on_sleep
#!/bin/bash
touch ~/Desktop/touchfile_my_script_acpi
case "$1" in
hibernate|suspend)
sh -c "/home/king/Desktop/Scripts/rotate_desktop normal; /home/king/Desktop/Scripts/misc/my_keyboard on" 2> ~/Desktop/revert_kb_error_log.txt ;;
#thaw|resume)
king#death-star /etc/acpi $ ls
total 1MB
drwxr-xr-x 3 root root 1MB Jun 11 23:36 .
drwxr-xr-x 163 root root 1MB Jun 11 23:41 ..
-rwxr-xr-x 1 root root 1MB Jun 11 23:36 01_revert_kb_on_sleep
king#death-star /etc/acpi $ ps -ef| grep acpid
root 1070 1 0 23:41 ? 00:00:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
king 3499 2574 0 23:52 pts/2 00:00:00 grep --colour=auto acpid
Step 1.
a. Enable and start the acpi service.
b. Run the acpi_listen command and try putting the computer to sleep via various methods (pushing the power button, closing the lid, etc.)
c. Find out what events are triggered, when you do the above. In my case they were: button/lid LID close and button/sleep SBTN 00000080 00000000
Step 2.
a. Create the file /etc/acpi/events/my_events with the following:
event=(button/sleep SBTN|button/lid LID close)
action=/etc/acpi/my_script.sh
Substitute the events in the event= line with your events.
b. Create the file /etc/acpi/my_script.sh with the following:
#!/bin/sh
/home/king/Desktop/Scripts/rotate_desktop normal
/home/king/Desktop/Scripts/misc/my_keyboard on
NB. You might need to add export DISPLAY=:0 before the scripts to get access to your X session.
NB2: Your scripts will run with root user credentials. To run with your user credentials, you might want to do:
sudo -u king /home/king/Desktop/Scripts/rotate_desktop normal
sudo -u king /home/king/Desktop/Scripts/misc/my_keyboard on
c. Make the file /etc/acpi/my_script.sh executable:
chmod +x /etc/acpi/my_script.sh
d. Restart the acpi service.
Step 3. Share and enjoy.