LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 12-28-2019, 12:17 PM   #1
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Rep: Reputation: Disabled
Bash scriipt calling Konsole in Sudo Mode


All,

I'm running Kubuntu, so it is "Konsole", not "Terminal" on my box. I need a bash script that does the following:
  1. Kills any current Konsole sessions,
    Guessing it is the cmd: myvar < ps -A | grep konsole && kill $myvar
  2. Re-opens Konsole with 3 session tabs,
  3. Logs each tab session into sudo mode for root
I need to register this in the Login Registry so I always have these 3
Konsole sessions open at the start of any login on my computer.

It's such a pain to have to manually do this every time I login.

Ideally, for security, the command will be:
Code:
bash /...path.../sudologin.sh mypass
which will also allow it's call at anytime and be used by any linux user and also allow, with the right symlink or rc registry, it to be called without the path name. Non KDE users will use "terminal" not konsole.

All help appreciated!

Cheers!

TBNK

Last edited by TBotNik; 12-28-2019 at 12:20 PM.
 
Old 12-28-2019, 12:48 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
sounds like a lot to figure out, your side panel says you've been using Linux for at least 3 yrs now, what have you figured out so far, other then the steps of operation?

using a Konsole, or you can install a different terminal to work in so it does not kill that one while you're working on figuring out how to kill a current Konsole terminal. work out the steps in a cli then add to a script test, fix, repeat until you get it. one step at a time.

somethink like this to kill kill kill the terminals
Code:
ps ux | grep xfce4-terminal | xargs kill
xfce4-terminal --tab -T one 
xfce4-terminal --tab -T two
xfce4-terminal --tab -T three
got a look up how your terminal you're going to use is used to do these things.
 
Old 12-28-2019, 01:10 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,138
Blog Entries: 6

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
Quote:
Kills any current Konsole sessions
pkill Konsole

Quote:
Re-opens Konsole with 3 session tabs,
https://docs.kde.org/trunk5/en/appli...ole/index.html
https://docs.kde.org/trunk5/en/appli...e-options.html

Quote:
Logs each tab session into sudo mode for root
See:
man sudo
man sudoers
man kill
man pgrep
man ps
man killall
 
Old 01-23-2020, 12:37 PM   #4
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Progress

Quote:
Originally Posted by teckk View Post
pkill Konsole


https://docs.kde.org/trunk5/en/appli...ole/index.html
https://docs.kde.org/trunk5/en/appli...e-options.html


See:
man sudo
man sudoers
man kill
man pgrep
man ps
man killall
teckk,

From what you are saying my script needs to say:
Code:
curdir='$pwd;
cd /Scripts/Extras/
pkill konsole;
konsole --tabs-from-file ktabs.txt
But I have not found what to put into the ktabs.txt file to:
  1. Open the konsole with the tab bar at the top,
  2. open each tab with execution of: sudo su -u root -p mypass. I understand I need a line for every tab I open,
I'm still researching this but no progress so far!

Cheers!

TBNK
 
Old 01-23-2020, 12:49 PM   #5
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
All,

On the Redhat and Suse flavors of Linux the cli cmd:
Code:
kdesu konsole
works but on the debian and Ubuntu flavors the cli cmd:
Code:
konsole -e "su -"
is the working cmd for opening a new konsole session.

Since I'm attempting the opening of multiple tabs, needing the ktabs.txt file, not sure where to put this command set, in the ktabs.txt file or before it?

Cheers!

TBNK

Last edited by TBotNik; 01-23-2020 at 12:55 PM.
 
Old 01-23-2020, 01:08 PM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
It seems that other terminals are better than konsole nowadays. But with konsole,

Code:
#!/bin/sh

pkill -x konsole
konsole -e su - & pid=$!
konsole --new-tab -e sudo -i exec /bin/bash
konsole --new-tab -e sudo -i exec /bin/bash
konsole --new-tab -e sudo -i exec /bin/bash

echo $pid

exit 0
 
Old 01-23-2020, 01:35 PM   #7
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Code

All,

The code I currently have is Bash Script:
Code:
#! /bin/bash
# Script to login to SUDO mode
# CMD: bash /Scripts/Extras/sudologin.sh

# Get the current dir to enable return to it
curdir=$pwd;
cd "/Scripts/Extras/";
# kill the current konsole sessions
pkill konsole;
# Restart konsole in sudo mode with tabs from the file
konsole -e "su -" --tabs-from-file ktabs.txt
# Return to the starting dir
cd $curdir;
and the "ktabs.txt file of:

Code:
#! ktabs.txt file

title: Konsole%n;; workdir: /home/files;; profile: Shell
title: Konsole%n;; workdir: /home/files/Dropbox;; profile: Shell
title: Konsole%n;; workdir: /Scripts; profile: Shell
The problem here is when executed from Konsole the kill terminates the commands, so unless it is somehow stored in memory the remaining "restart" does not execute. I'm
adding this to a custom application launcher to get around this, but if you know the way to store this command set for continued execution it would be nice.

Out of curiosity I'm wondering if the "nohup" background run cmd will work?

Cheers!

TBNK
 
Old 01-23-2020, 01:36 PM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
The -e option should be the last item on the line.
 
Old 01-23-2020, 01:44 PM   #9
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
I ran my code, both from a launcher and from an "F2" window piping to error file and got no errors, but also the 3 knosole sessions did not apprear, so there is something wrong with the code.

Cheers!

TBNK
 
Old 01-23-2020, 01:47 PM   #10
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
The -e option should be the last item on the line.
Turbocapitalist,

Thanks! Moving the -e to the end of the line, it now executes only I'm just only getting 2 tabs and none are in the sudo mode.

Cheers!

TBNK
 
Old 01-23-2020, 01:56 PM   #11
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
All,

OK found the issue with the 3rd tab in the ktabs.txt file but now wondering if the sudo cmd needs to be in that file at the end of each tab line, since none of the sessions are coming up "SUDO"?

Cheers!

TBNK
 
Old 01-23-2020, 02:03 PM   #12
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Here is an example:

Code:
#!/bin/sh

t=$(tempfile ktabs.XXXXX) || exit 1

cat <<EOT > ${t}
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh

EOT

pkill -x konsole

konsole --tabs-from-file ${t}

sleep 1

rm -f ${t}

exit 0
If there is still difficulty, try adding "set -xv" as the second line.

Last edited by Turbocapitalist; 01-23-2020 at 02:07 PM.
 
Old 01-24-2020, 02:12 PM   #13
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Here is an example:

Code:
#!/bin/sh

t=$(tempfile ktabs.XXXXX) || exit 1

cat <<EOT > ${t}
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh
title: %n;; workdir: /tmp/;; profile: default;; command=/usr/bin/sudo -i /bin/sh

EOT

pkill -x konsole

konsole --tabs-from-file ${t}

sleep 1

rm -f ${t}

exit 0
If there is still difficulty, try adding "set -xv" as the second line.
Turbocapitalist,

Thanks, but didn't work! Still never logs to SUDO mode!

Cheers!

TBNK
 
Old 01-24-2020, 02:22 PM   #14
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TBotNik View Post
Turbocapitalist,

Thanks! Moving the -e to the end of the line, it now executes only I'm just only getting 2 tabs and none are in the sudo mode.

Cheers!

TBNK
Turbocapitalist,

I see in some HOWTOs that it's -c for a cmd instead of -e to execute, but my system runs the -e. My question then is should the -e be in the ktabs.txt file. And should that replace the:
Code:
command=/usr/bin/sudo -i /bin/sh
you showed in your script as that "command=/usr/bin/sudo -i /bin/sh" is not working. Also should it be the actual cli cmd of "sudo su -u root -p mypass"? That would have the end of each tab line of:
Code:
-e sudo su -u root -p mypass
So I tried that and no change not coming up SUDO!

I'm seeing this is one of those: "Hold your mouth just right!" situations! He He!

Cheers!

TBNK

Last edited by TBotNik; 01-24-2020 at 02:28 PM.
 
Old 01-24-2020, 02:31 PM   #15
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Turbocapitalist,

Would it be that my script needs to call another script the uses a for loop to find each konsole tab and execute the "sudo su -u root -p mypass" cmd on each tab?

Cheers!

TBNK
 
  


Reply

Tags
bash, konsole



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vfork - suspends the calling process or the calling thread? zmau Linux - Software 3 04-21-2015 02:38 PM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Konsole always give SuperUser Konsole - can't get regular shell checkmate3001 Linux - Desktop 3 08-05-2008 10:00 AM
konsole acts as "Root Konsole" ab44045 Linux - General 11 06-11-2007 05:18 PM
odd recursion: calling "by hand" vs calling by cronscript... prx Programming 4 02-12-2005 04:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration