Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: su & and password problems in init.d-scripts

  1. #1
    Join Date
    Jun 2007
    Location
    Sweden
    Beans
    28

    Arrow su & and password problems in init.d-scripts

    Hi.

    I have written (or at least I'm trying) a script that will close a session of screen when the system is going down (rc0) or rebooting (rc6).

    I have placed this script in /etc/init.d/ and chmoded it u+x.
    Code:
    #!/bin/bash
    # Script name = irctor
    
    case $1 in
    start)
      /home/xxxxx/bin/screen/start.sh
      ;;
    stop)
      su --login -c 'screen -S irctor -X quit' xxxxx
       ;;
    esac
    
    # test if the scripts runs
    echo 'It do works' > /home/xxxxx/works.txt
    I have also made symbolic links to rc0 and rc06 which I added with the tool sysv-rc-conf

    Code:
    xxxxx@compton:~$ cd /etc/rc0.d/
    xxxxx@compton:/etc/rc0.d$ ls -l *irctor*
    lrwxrwxrwx 1 root root 16 2008-07-02 14:26 S74irctor -> ../init.d/irctor
    xxxxx@compton:/etc/rc0.d$ cd /etc/rc6.d/
    xxxxx@compton:/etc/rc6.d$ ls -l *irctor*
    lrwxrwxrwx 1 root root 16 2008-07-02 14:35 S74irctor -> ../init.d/irctor
    It looks OK I think. If I have understood everything right links in runlevel 0 or 6 will be called with the parameter 'stop' which will in this case stop the session of screen named irctor.

    But the thing is that screen-sessions are user-bound so root can't (at least I think) access or stop screen sessions that I (erikw) have started. To solve this you should probably use the command su like I did in the /etc/init.d/irctor script but the problem with that is that su seems to required a password input to continue executing to command.

    My question is: how do i get around the enter-password-thing?

    Any help is appreciated! ( I have red this manual or what is it)
    Last edited by howefield; February 10th, 2019 at 02:17 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    Germany - Berlin
    Beans
    340

    Re: su & and password problems in init.d-scripts

    Root can stop them, root can stop every process running (apart from zombie processes).

    for the stop I would either do
    su - xxxxx -c 'screen -S irctor -X quit'
    or to make it work for other user too:
    killall irctor
    Last edited by howefield; February 10th, 2019 at 02:18 PM.

  3. #3
    Join Date
    Jun 2007
    Location
    Sweden
    Beans
    28

    Re: su & and password problems in init.d-scripts

    @Gunman1982: I don't think root can quit screen sessions. Look here:

    Code:
    xxxxx@compton:~$ screen -ls
    There is a screen on:
    	5270.irctor	(Detached)
    1 Socket in /var/run/screen/S-erikw.
    
    xxxxx@compton:~$ sudo su
    root@compton:/home/erikw# screen -ls
    No Sockets found in /var/run/screen/S-root.
    and the "su - xxxxx -c 'screen -S irctor -X quit'" seems to required a password so how can I automate that?
    Last edited by howefield; February 10th, 2019 at 02:18 PM.

  4. #4
    Join Date
    Jul 2008
    Beans
    17

    Re: su & and password problems in init.d-scripts

    Quote Originally Posted by Ballena View Post
    My question is: how do i get around the enter-password-thing?
    I heard about a language called Expect that allow to interact with a program directly instead of using the stdin/stdout pipeline stuff. You can install it from the repository. I have tried this litle program:

    Code:
    #!/usr/bin/expect -f 
    spawn su username
    expect "Password" 
    send "userpassword\n"
    interact
    And it works fine. Maybe that can help you.

    Homepage: http://expect.nist.gov/
    Tutorial: http://dslab.lzu.edu.cn/docs/summer_.../tutorial.html

    By the way, get around the password that way should work, but I don't think it's the better solution. Anyway, I'm not a "screen" user so I have nothing else to propose.

    I hope this helps

  5. #5
    Join Date
    Jun 2007
    Location
    Sweden
    Beans
    28

    Re: su & and password problems in init.d-scripts

    @Frozsyn: That sure sounds interesting! But you are probably right that it's maybe not the best solution. Are there no other ways of closing screen sessions the belongs to another user than actually su that user?

  6. #6
    Join Date
    Mar 2006
    Location
    Nerderlands
    Beans
    1,349
    Distro
    Ubuntu

    Re: su & and password problems in init.d-scripts

    "su - xxxxx -c 'screen -S irctor -X quit'"

    that should not require a passwd, if you do that as root..

    Root may su to anyuser w/o passwd prompt
    Last edited by howefield; February 10th, 2019 at 02:19 PM.
    "Please choose a different password, the one you have chosen is in use by UID 1432"

  7. #7
    Join Date
    Jun 2007
    Location
    Sweden
    Beans
    28

    Re: su & and password problems in init.d-scripts

    @justleen: You seems to be right because I could execute that command as root whitouy a prompt for password. But the script is still not run (which I know since no works.txt file can be found in my home directory) when changing run level to poweroff or reboot.

    What more is required for a script to run in a run level then what I already have done? The script takes the argument start and stop and symbolic links to the script in /etc/init.d/ exists n both /etc/rc0.d/ and /etc/rc6.d/.

  8. #8
    Join Date
    Jul 2008
    Beans
    17

    Re: su & and password problems in init.d-scripts

    @Ballena: I have try to simply terminate the SCREEN processes by using the kill commance, and it works pretty good, and screen terminate correctly. Is there any reason why you do not want to use the kill command (or killall proposed by Gunman1982) ? A more screen way to do is maybe to use the multiuser mode. Have you try to use the multiuser mode and add the user root to the acl ?

  9. #9
    Join Date
    Jul 2008
    Beans
    17

    Re: su & and password problems in init.d-scripts

    Have you try to put your "echo 'It do works' > /home/xxxxx/works.txt" at the beginning of your init script file too? Maybe the script is called and never finish for some reason...
    Last edited by howefield; February 10th, 2019 at 02:19 PM.

  10. #10
    Join Date
    Apr 2008
    Location
    Germany - Berlin
    Beans
    340

    Re: su & and password problems in init.d-scripts

    I assume your script will be executed but you can't see it using such a file becaus of the /etc/rc0.d/S60umountroot after that script you can't access your home anymore, therefor not write in it. make a different link K10irctor.

    And what I meant with using killall is that you actually shut down the process (irctor?) you run in the screen instead of shutting down the screens. You can shutdown the screens with as root too. Do a 'killall screen' as root or rather if you want to test it with sudo and see what happens to your started screen sessions.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •