Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[solved] Bad return value upon login ?

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

[solved] Bad return value upon login ?

#1 Post by DoubleHP »

Hello.

I have modified my bashrc to add to my prompt the return value of last command. This works fine on most machines, but one.

Upon login, most machines report 0 (true). But one machine reports false. Login process is fine; but inside the tasget host, the prompt reports 1 just at login time.

After digging, I have to this:

Code: Select all

# head /etc/profile
echo 4
return 5
And during login:

Code: Select all

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Feb 11 18:15:26 2019 from 2a01:e35:xx
4
-bash-4.4# echo $?
1
-bash-4.4# echo $?
0
-bash-4.4#
As you see, I was expecting 5, but got 1. How to dig deeper than profile ? who loads profile ? What represents $? on the very first execution of prompt ? Is there a way to force $? to 0 ? for example, ending bashrc with true did not help.
Last edited by DoubleHP on 2019-02-11 20:16, edited 2 times in total.

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Bed return value upon login ?

#2 Post by bw123 »

...but login hasn't exited, so there wouldn't be a value yet? Probably the return/exit code from the last command preceding login...?

Strange issue, not sure where I'd look. Probably syslog, or the journal? Could it be motd? lastlog? just guessing. Anything executed in a startup like ~.bashrc might be another guess.

too busy to look it up...
https://duckduckgo.com/html/?q=linux+pid+last+command
resigned by AI ChatGPT

DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

Re: Bed return value upon login ?

#3 Post by DoubleHP »

So, when logging via ssh, what is run before the bash shell ? And what's the parent ?

I have found that the parent of bash is sshd (user cession).

Is it sshd which prints motd and reads password to know which shell to execute ?

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: Bed return value upon login ?

#4 Post by Head_on_a_Stick »

Not sure about ssh but check the FILES section of the bash man page, Debian uses ~/.profile instead of ~/.bash_profile though.

Reserved exit codes are listed here: https://www.tldp.org/LDP/abs/html/exitcodes.html
deadbang

DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

Re: Bad return value upon login ?

#5 Post by DoubleHP »

You are just right.

~/.bashrc was ending with "mesg n", and adding a new line with "true" fixed my issue.

For some reason, this command produces various return values on various machines.

Issue fixed for me. Thanks.

Machines where "mesg n" returns 0 :

Code: Select all

# mesg --help
Usage: mesg [y|n]
Where it returns 1:

Code: Select all

# mesg -V
mesg from util-linux 2.29.2

Post Reply