Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8087981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:57:13+00:00 2026-06-05T18:57:13+00:00

I have a Bash script on server A that finds the logged in SSH

  • 0

I have a Bash script on server A that finds the logged in SSH user via the logname command, even if it’s run as root with sudo. If I SSH into server A from my desktop and run the script, it works fine.

However, I’ve set up a post-commit hook on SVN server S which SSH’s into A and runs the script there, which causes logname to fail, with error “logname: no login name”.

If I SSH into S from my desktop, then SSH into A from there, it works correctly, so the error must be in the fact that the SVN hook ultimately does not run from a virtual terminal.

What alternative to logname can I use here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:57:14+00:00Added an answer on June 5, 2026 at 6:57 pm

    You could use the id command:

      $ ssh 192.168.0.227 logname
      logname: no login name
    

    However

      $ ssh 192.168.0.227 id
      uid=502(username) gid=100(users) groups=100(users)
    

    In a bash script you can cut the username out of the id output with something like

      $ id | cut -d "(" -f 2 | cut -d ")" -f1
      username
    

    To have a script that works both in a sudo environment and without a terminal you could always execute different commands conditionally.

    if logname &> /dev/null ; then 
        NAME=$( logname )
    else 
        NAME=$( id | cut -d "(" -f 2 | cut -d ")" -f1 )
    fi
    echo $NAME
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this bash script on the server that runs every hour, via cron.
I have a bash script that uploads a file via SFTP, with a command
I have a Bash script that builds a string to run as a command
I have a bash script that runs (something like) the following command: vim -E
I have a bash script that does ssh to a remote machine and executes
I have a bash script which I wrote that lists out some servers/user names.
I have a KornShell (ksh) script in Server A that will run a script
I have a bash script that needs to perform a couple actions in MySQL.
I have a bash script that processes some data using inotify-tools to know when
I have a bash script that cuts out a section of a logfile between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.