You are not logged in.
Pages: 1
Hello,
I try to run this script.
#!/bin/bash
sudo /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin &
The sudoers entry
%users ALL= NOPASSWD: /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin
I get the following error!
$ Passwort: sudo: pam_authenticate: Kommunikationsfehler
Kommunikationsfehler = eng: communication error
What's wrong with that?
Thank you!
clementis
Offline
Can't you issue any sudo command without an error?
Offline
i dont know if it matters, but in my sudoers, i have the syntax
%users ALL=(ALL)NOPASSWD: command
dont know if the (ALL) makes a difference, but give that a shot.
Desktop/Laptop - DWM :: VM - screen
Registered Linux User Number 483137 :: Victory! :: GitHub
Offline
i dont know if it matters, but in my sudoers, i have the syntax
%users ALL=(ALL)NOPASSWD: command
dont know if the (ALL) makes a difference, but give that a shot.
I don't have that, and it works fine for me. So, that's probably not the case.
Offline
yes, I can run command as sudo without error!
Just this script doesn't work.
I changed sudoers to
tom ALL=(ALL) ALL
%users ALL= NOPASSWD: /bin/cat /dev/input/event1
just to get certain that sudoers is not faulty.
I also created an alias
alias event1='sudo /bin/cat /dev/input/event1 >> $HOME/.cblog/log.bin &'
Now the script and the alias are running without problems.
But I can't autostart it in xfce!
Any hints?
Thank you!
Clementis
Offline
I don't really understand your /etc/sudoers.
alias event1='sudo /bin/cat /dev/input/event1 >> $HOME/.cblog/log.bin &'
You are aliasing something inside your alias...
What do you mean, "can't autostart"? Won't it autostart, don't you know how to autostart? Please be more precise.
Offline
Sorry, for being not precise.
I created the alias in .bashrc in my $home directory. In sudoers all users are allowed to key in this command without a passwort entry.
I know how to autostart in xfce and so created an autostart entry but unfortunatly it doesn't work for my "special" command.
What I did:
1. I wrote a script (first post) and tried to autostart it in xfce. For that command I created an entry in sudoers in order to avoid enter root passwort. The script didn't start.
Then...
2. I created an autostart entry (deleted the first one - see point 1) and entered the whole command (cat .../event1 >> $home...) in the xfce autostart input window. The idea was to run the command directly and not through a script. But it didn't work.
Therefore I tried to run alter the command to "bash cat .../event1 >> $home ...." Didn't work either.
3. I also deleted the autostart entry no 2. and created the alias in .bashrc in my home directory. Now created a new autostart entry trying to start the alias. Didn't work.
I also tried to set the Terminal option in the file $home/.config/autostart/log.desktop to "true".
So it looked like this:
[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=log
Comment=event1
Exec= sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
StartupNotify=false
Terminal=true
Hidden=false
The alias for example works well if I enter it in xterm.
So, I don't know why it isn't working! :-(
Thank you for any help
Clementis
Offline
Not sure if this is your problem, but if you issue a command like
sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin
The command "cat /dev/input/event1" is executed as root, but the >> redirect only has user permissions. If you want the redirect to write as root use something like:
sudo sh -c "cat /dev/input/event1 >> /home/tom/.cblog/log.bin"
Offline
regarding the alias not working in the xfce autostart, this might shed some light on that.
//blue/0/~/ grep ^alias\ tester .bashrc
alias tester='echo this is from an alias'
//blue/0/~/ tester
this is from an alias
//blue/0/~/ bash -c 'tester'
bash: tester: command not found
//blue/127/~/ bash -cli 'tester'
this is from an alias
man bash to see what the -l and -i options are actually doing. (for instance, -i might not be needed depending on how your .bashrc is set up).
edit: i also dunno how xfce likes spaces in the autostart thing, worth a double check:
Exec= sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
Last edited by brisbin33 (2009-11-09 18:27:02)
//github/
Offline
Hmmm - maybe put double quotes around it?
Offline
dont know if the (ALL) makes a difference, but give that a shot.
"man sudoers"
[git] | [AURpkgs] | [arch-games]
Offline
Thx!
I gave all your suggestions a try but nothing worked. A Terminal is autostarted but the command is not executing. I only see the black xterm window, the prompt is missing i.e. the cursor is at the beginning of the line without a prompt.
If I execute the command in the Alt+F2 window I get the same result.
If executing the command directly in the terminal it works perfectly.
Any hints! Please!
Clementis
Offline
You might want to try this:
Exec= sudo xterm -e cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
OR
Exec= xterm -e sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
I used something similar with another terminal emulator when using Open Box. It should work out perfectly and the console will exit after the command is executed.
Offline
You cannot use sudo with a redirection. The redirection is parsed by bash, it is not an argument to sudo. The only way is to use su, or write a script.
[git] | [AURpkgs] | [arch-games]
Offline
I created an alias for the command in bash.rc. Running the alias in a terminal window is no problem. If I press Alt+F2 and key in "bash -cli "event1"" (event1 is my alias) it also works perfect.
Nothing worked, i.e. it seems that autostarting that command is not possible.
Maybe someone knows a way to run the command before x starts.
Offline
Have you tried putting the command in your rc.local file?
Offline
I wasn't aware you could redirect output with sudo'd permissions, but the sudoers manpage educated me with an example. I got the following from 'man sudoers' but modified the command:
Run visudo. Add the line:
%wheel ALL=NOPASSWD: /bin/sh -c "cat /etc/fstab.secure >> /joe.txt"
And now I can sudo with that command from a terminal or from a run box with no problems and no password prompt. The big things are the full path to sh and the quotes around the command, but nowhere else.
I just had to make an /etc/fstab.secure (copy of my fstab set to chmod 700) and was able to write the joe.txt file to my root (which my user cannot write to). I deleted /joe.txt and ran the command again from a run box. Nothing displayed on the screen at all, but when I checked, joe.txt had been successfully written to my root directory. Maybe it'll work for you (with your command in the quotes, obviously).
Lewis
To understand recursion, you must understand recursion.
Offline
Oh, if you use my example, you might what to do %users instead of %wheel, but that shouldn't change anything. (I just noticed you were trying users in your example).
To understand recursion, you must understand recursion.
Offline
@Lewis: running the command in a terminal is *not* a problem - it works!
The problem is the autostart. The autostart does not work!
Any idea?
@anonymous user: yes I tried putting the command in rc.local but then I had problems booting the notebook. That means that the boot process didn't finish. It stopped while executing the command. I had to run a live cd to correct it.
Offline
Oh. I figured it wasn't working from your log.desktop file because of the alias, and you wanted to know how to do it without a bash alias... That's why my example was of redirection without an alias.
Hmm... Pre-X... What login manager do you use?
Since I use slim and it calls xinit, I just put things that I want to autostart in my ~/.xinitrc
To understand recursion, you must understand recursion.
Offline
Pages: 1