Results 1 to 8 of 8

Thread: KATE - Cannot start kate from script as another normal user

  1. #1
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,037

    Default KATE - Cannot start kate from script as another normal user

    Hello.

    Purpose
    Run script as root because access to files in /etc
    Build a list of files to edit
    When list is complete call a script as normal user to compare/edit pair of files in the list ( normal_user files )
    I start a script from .desktop file as root user

    Code:
    [Desktop Entry]
    Comment[en_US]=cmp diff with first install
    Comment=cmp diff with first install
    Exec=/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install d
    GenericName[en_US]=cmp diff with first install
    GenericName=cmp diff with first install
    Icon=yast-geo-cluster
    MimeType=
    Name[en_US]=cmp diff with first install
    Name=cmp diff with first install
    Path=
    StartupNotify=true
    Terminal=true
    TerminalOptions=\s--noclose
    Type=Application
    X-DBUS-ServiceName=
    X-DBUS-StartupType=none
    X-KDE-SubstituteUID=true
    X-KDE-Username=root
    At then end of the script, when the job is finished I call another script for a standard user
    Code:
    #
    # we are root
    #
    CUR_USER="some_user"
    chmod -v 777 /tmp/files_find_new_config_after_install*
    chown -v $CUR_USER:users /tmp/files_find_new_config_after_install*
    chown -v $CUR_USER:users /backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff
    
    export $(dbus-launch)
    su -c "/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff \"$OUTPUT_FILE_EDIT_LIST_DIFFER\"  DIFFER " -m $CUR_USER
    su -c "/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff \"$OUTPUT_FILE_EDIT_LIST_EQUAL\"  EQUAL " -m $CUR_USER
    
    exit
    here the sub script called by root ( su -c ".................. )
    Code:
    if [[ $# -gt 0 ]] ; then
    
        INPUT_FILE="$1"
        SESSION_NAME="$2"
        echo "INPUT_FILE   : $INPUT_FILE"
        echo "SESSION_NAME : $SESSION_NAME"
        echo "DISPLAY : $DISPLAY"
    
        set -x
    
        OIFS="$IFS"
        IFS=$'\n'
        while IFS='' read -r line || [[ -n "$line" ]]; do
            SOURCE_FILE="$line"
            echo "FILE : $SOURCE_FILE"
            DISPLAY=:0 kate --start $SESSION_NAME $SOURCE_FILE &
        done < "$INPUT_FILE"
        IFS="$OIFS"
    
        set +x
        
    else
        exit 255
    fi
    here the following errors

    Code:
    ..................
    ..................
    ..................
    
    ++ DISPLAY=:0
    ++ kate --start EQUAL ' /home/some_user/.config/kcookiejarrc '
    ++ DISPLAY=:0
    ++ kate --start EQUAL ' /home/some_user/.config/kaccessrc '
    ++ DISPLAY=:0
    ++ kate --start EQUAL ' /home/some_user/.kde4/share/config/kcminputrc '
    
    ..................
    ..................
    ..................
    
    No protocol specified
    QXcbConnection: Could not connect to display :0
    No protocol specified
    QXcbConnection: Could not connect to display :0
    No protocol specified
    QXcbConnection: Could not connect to display :0
    
    ..................
    ..................
    ..................
    Any help is welcome.
    Thanks for helping. JCD
    __________
    server leap 15.0 -- ASUS g75vw KDE leap 15.0 -- ASUS g750JZ Optimus KDE leap 15.1 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,296
    Blog Entries
    2

    Default Re: KATE - Cannot start kate from script as another normal user

    Recommend do not invoke any graphical apps, is there any good reason to invoke Kate (usually there isn't).

    Also,
    I don't seem to see what you're testing or diffing, but are you sure simply running diff wouldn't do what you want more simply?
    (I'm referring to the common utility "diff")

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  3. #3

    Default Re: KATE - Cannot start kate from script as another normal user

    It might be good to state the actual point of this. For diffing changed files it seems overly complicated. Also, if you really, really need graphical representation, why not use a diff app like kompare that shows changes side by side?

    Regarding the user switch: You know that root can edit files of other users without changing the file owner, right? Or the other way around: run as user and get file lists with sudo. Which would be preferred anyway.

    For graphical connection: given that there actually is an xserver running, you probably need to fiddle with XAUTHORITY on the active display. Another option would be fake remote ssh connections like 'ssh -Y some_user@localhost kate' which should open kate on the current desktop.

  4. #4
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,037

    Default Re: KATE - Cannot start kate from script as another normal user

    Quote Originally Posted by tsu2 View Post
    Recommend do not invoke any graphical apps, is there any good reason to invoke Kate (usually there isn't).

    Also,
    I don't seem to see what you're testing or diffing, but are you sure simply running diff wouldn't do what you want more simply?
    (I'm referring to the common utility "diff")

    TSU
    Purpose
    Run script as root because access to files in /etc
    Build a list of files to edit
    When list is complete call a script as normal user to compare/edit pair of files in the list ( normal_user files )
    And my very simple question was how to start kate from script.
    Thanks for helping. JCD
    __________
    server leap 15.0 -- ASUS g75vw KDE leap 15.0 -- ASUS g750JZ Optimus KDE leap 15.1 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  5. #5
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,037

    Default Re: KATE - Cannot start kate from script as another normal user

    Quote Originally Posted by markdd View Post
    It might be good to state the actual point of this. For diffing changed files it seems overly complicated. Also, if you really, really need graphical representation, why not use a diff app like kompare that shows changes side by side?

    Regarding the user switch: You know that root can edit files of other users without changing the file owner, right? Or the other way around: run as user and get file lists with sudo. Which would be preferred anyway.

    For graphical connection: given that there actually is an xserver running, you probably need to fiddle with XAUTHORITY on the active display. Another option would be fake remote ssh connections like 'ssh -Y some_user@localhost kate' which should open kate on the current desktop.
    > It might be good to state the actual point of this. For diffing changed files it seems overly complicated. Also, if you really, really need graphical representation, why not use a diff app like kompare that shows changes side by side?

    You cannot edit within kompare

    > Regarding the user switch: You know that root can edit files of other users without changing the file owner, right? Or the other way around: run as user and get file lists with sudo. Which would be preferred anyway.

    I know all that. My problem is not building the list one way or another.

    >For graphical connection: given that there actually is an xserver running, you probably need to fiddle with XAUTHORITY on the active display. Another option would be fake remote ssh connections like 'ssh -Y some_user@localhost kate' which should open kate on the current desktop.

    This is exactly what I don't want to do.
    Up to leap 42.2 it was possible to start kate from script.

    Now it seems we are going back to code on a punched card.

    >For graphical connection: given that there actually is an xserver running, you probably need to fiddle with XAUTHORITY on the active display.

    Have you a tip.

    Thank you for your comments.
    Thanks for helping. JCD
    __________
    server leap 15.0 -- ASUS g75vw KDE leap 15.0 -- ASUS g750JZ Optimus KDE leap 15.1 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  6. #6
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,296
    Blog Entries
    2

    Default Re: KATE - Cannot start kate from script as another normal user

    You can do all this without a graphical app...

    Use diff to compare files, then your logic can perhaps invoke sed(or awk) to replace test strings in the content.

    Or, skip the step to diff the files,
    Just run your string replacement against all files, and if the specified string to replace isn't in the file, then you've only lost the time to inspect the file contents line by line and nothing will be changed. In fact, if your individual files are very small, then this approach might even be faster than diffing files in the first place.

    There is always a big penalty if you switch between graphical and non-graphical apps so you need to carefully determine your reason for invoking a graphical app... and even in those cases there can be an ncurses based utility to display your info in graphical text form.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  7. #7
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,037

    Default Re: KATE - Cannot start kate from script as another normal user

    Quote Originally Posted by jcdole View Post
    Hello.
    ...................
    ...................
    ...................
    At then end of the script, when the job is finished I call another script for a standard user
    Code:
    #
    # we are root
    #
    CUR_USER="some_user"
    chmod -v 777 /tmp/files_find_new_config_after_install*
    chown -v $CUR_USER:users /tmp/files_find_new_config_after_install*
    chown -v $CUR_USER:users /backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff
    
    export $(dbus-launch)
    su -c "/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff  \"$OUTPUT_FILE_EDIT_LIST_DIFFER\"  DIFFER " -m $CUR_USER
    su -c "/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff  \"$OUTPUT_FILE_EDIT_LIST_EQUAL\"  EQUAL " -m $CUR_USER
    
    exit
    ...................
    ...................
    ...................
    Replacing the piece of code ( red one above ) by
    Code:
    su -c  "/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff_launcher   \"$OUTPUT_FILE_EDIT_LIST_DIFFER\"   \"$OUTPUT_FILE_EDIT_LIST_EQUAL\"    &   "   -m  $CUR_USER
    Now putting the code (red one above) in the launcher '/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff_launcher'

    Code:
    
    /backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff   "$1"   &
    /backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff   "$2"   &
    
    Now the last script which has not changed

    Code:
    if [[ $# -gt 0 ]] ; then
    
        INPUT_FILE="$1"
        echo "INPUT_FILE   : $INPUT_FILE"
        echo "DISPLAY : $DISPLAY"
    
        OIFS="$IFS"
        IFS=$'\n'
    
        EDIT_FILE=""
        while IFS='' read -r line || [[ -n "$line" ]]; do
            SOURCE_FILE="$line"
            echo "FILE : $SOURCE_FILE"
            EDIT_FILE="$EDIT_FILE \"$SOURCE_FILE\"   "
        done < "$INPUT_FILE"
    
        IFS="$OIFS"
    
        DISPLAY=:0  kate -n  "$EDIT_FILE"   &
    
    else
        exit 255
    fi
    Do the job.

    Thank you every body for helping.
    Thanks for helping. JCD
    __________
    server leap 15.0 -- ASUS g75vw KDE leap 15.0 -- ASUS g750JZ Optimus KDE leap 15.1 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  8. #8
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,037

    Default Re: KATE - Cannot start kate from script as another normal user

    Quote Originally Posted by tsu2 View Post
    Use diff to compare files, then your logic can perhaps invoke sed(or awk) to replace test strings in the content.
    TSU
    No, because a priori I don't know what files differ, where the changes are and what to change by.

    Any way thank you for helping.
    Thanks for helping. JCD
    __________
    server leap 15.0 -- ASUS g75vw KDE leap 15.0 -- ASUS g750JZ Optimus KDE leap 15.1 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

Posting Permissions

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