LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-01-2020, 11:39 AM   #1
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Rep: Reputation: Disabled
Sudo Hostname


All,

Having an issue with a BASH script where it needs the hostname running the sudo cmd!

The /etc/hosts file has these settings:

Code:
 i
127.0.0.1	localhost
127.0.1.1	Aspire-LT

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
which usually mean running the cmd "hostname" will return the value from 127.9.1.1, but running that cmd it only says "(none)".

The cmd running in the script is:

Code:
konsole --tabs-from-file ktabs.txt -exv "su -u root -p $mypss"
which is to open the konsole in sudo mode.

Because of the hostname error sudo is not working correctly!

So where do I set the hostname that sudo is looking for?

Any ideas? Thanks!

Cheers!

TBNK

Last edited by TBotNik; 05-01-2020 at 11:43 AM.
 
Old 05-01-2020, 11:50 AM   #2
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
PS,

File /etc/hostname is set at:

Code:
127.0.1.1       localhost
127.0.1.1       Aspire-LT
Cheers!

TBNK
 
Old 05-01-2020, 11:56 AM   #3
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
What is output of:
Code:
hostname
hostnamectl  | grep -i hostname
And if needed, you can set it:

Code:
hostnamectl set-hostname <hostname>
 
Old 05-01-2020, 12:11 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,913

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
1. do not mix sudo and su. These are two different tools.
Quote:
Originally Posted by TBotNik View Post
Having an issue with a BASH script where it needs the hostname running the sudo cmd!
Quote:
Originally Posted by TBotNik View Post
Code:
konsole --tabs-from-file ktabs.txt -exv "su -u root -p $mypss"
which is to open the konsole in sudo mode.
2. how do you know it? Are you sure about it?
Quote:
Originally Posted by TBotNik View Post
Because of the hostname error sudo is not working correctly!
 
Old 05-01-2020, 08:29 PM   #5
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by TBotNik View Post
Having an issue with a BASH script where it needs the hostname running the sudo cmd!
Here you're talking about sudo

Quote:
konsole --tabs-from-file ktabs.txt -exv "su -u root -p $mypss"

which is to open the konsole in sudo mode.
But here you're using su, not sudo!

Quote:
So where do I set the hostname that sudo is looking for?
Normally with "hostname <the name to set>"
Code:
# Set the hostname.
if [ -r /etc/HOSTNAME ]; then
  /bin/hostname $(cat /etc/HOSTNAME)
else
and as you can see in MY system the file that it is stored in is
/etc/HOSTNAME (all caps)

I've never heard of the file /etc/hostname (all lower case) and the one you quoted seems to be a subset of /etc/hosts

Furthermore the system library doesn't really support gethostname(2), the call that the hostname command uses:
Quote:
The GNU C library does not employ the gethostname() system call;
instead, it implements gethostname() as a library function that calls uname(2)
and copies up to len bytes from the returned nodename field into name.
and
Quote:
the field nodename is meaningless:
it gives the name of the present machine in some undefined network, but typically machines are in more than one network and have several names. Moreover, the kernel has no way of knowing about such things, so it has to be told what to answer here
(from the man pages gethostname(2) and uname(2)
So this suggests too that when never SET the hostname command returns nothing,
 
  


Reply



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
HOSTNAME = hostname -> HOSTNAME: command not found ? thomas2004ch Linux - Software 2 08-26-2013 08:25 PM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
sudo fails - "sudo: can't get hostname: Success" fantasygoat Linux - Server 3 10-01-2009 02:59 PM
hostname vs. HOSTNAME ? sirius56 Linux - Newbie 2 02-16-2007 08:16 AM
hostname command vs. $HOSTNAME env. variable Silly22 Linux - Networking 2 03-29-2002 05:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:27 PM.

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