Python and logname


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Python and logname
# 1  
Old 02-16-2010
Python and logname

How would i do this in python

In bash i would do below and this would add the users logname to a file
Quote:
echo "$(logname)" >> test.txt
This write the logname ie James to test.txt

But how would i do it in python this doesnt work below and ive tried different ways but cannot find an answer
Quote:
os.system("echo '$(logname)' >> test.txt")
But this just writes $(logname) to test.txt

Id really apprciate any helpSmilie
# 2  
Old 02-16-2010
Code:
os.system("echo ${LOGNAME} >> test.txt")

or
Code:
os.system("echo $LOGNAME >> test.txt")

# 3  
Old 02-16-2010
Ah! i tried that just got the wrong brackets, i should of know thatSmilie

ThankYouSmilieThankYouSmilieYhankYouSmilie
# 4  
Old 02-16-2010
Hey dave100:

The following is redundant and inefficient and needlessly complex:
Code:
echo "$(logname)" >> test.txt

You are capturing the output of logname only to echo it into test.txt, when you could have redirected it directly using
Code:
logname >> test.txt

With python:
Code:
os.system("echo ""$(logname)"" >> test.txt")

or
Code:
os.system("logname >> test.txt")


Alister
# 5  
Old 02-16-2010
Thanks all, your the best,Smilie that was last thing almost i had to work out, only thing left now
is to work out how to restart the python script from within its-self, but thats another problem
no doubt i will be posting another thread tomorrowSmilie

Dave
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

UNIX $USER and $LOGNAME environment variables

I have some comments about a previously closed topic whose name is the same as above Omitted from the discussion was the situation with a "sudo command or sudo within a script". There is an inconsistency between systems. On some systems $LOGNAME is invariant, on others, on RedHat sudo... (3 Replies)
Discussion started by: lsatenstein
3 Replies

4. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. SuSE

"ssh suse-server 'python -V' > python-version.out" not redirecting

Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here. I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
Discussion started by: Druonysus
3 Replies

6. Shell Programming and Scripting

Unix $USER and $LOGNAME environment variables

Hi, I am wondering what is the difference between the USER and LOGNAME environment variables, and under what situations would they be different? I am using Ubuntu 8.04 32-bit and I do not have 'login' command to test it. (7 Replies)
Discussion started by: royalibrahim
7 Replies

7. UNIX for Dummies Questions & Answers

LOGNAME

LOGNAME = 'id | awk '{begpos = index($0,"(") Endpos = index($ 0,")") print substr($0,begpos+1,endpos-begpos-1) }'; export LOGNAME -bash: syntax error near unexpected token `(' I am getting this error (5 Replies)
Discussion started by: sravani
5 Replies

8. AIX

How to make LOGNAME writeable? It is set as READONLY in .profile

LOGNAME variable is set as READONLY in .profile. I want to make it WRITEABLE so that I can modify the LOGNAME values programatically/throush shell programs. Thanks, Guru (1 Reply)
Discussion started by: gurubbc
1 Replies

9. HP-UX

logname error

when we log into HP servers randomly we will get the message "logname: could not get the login name" if we open another connection we can login we are running SSH 3.7 on OS B.11.23 this only happens on HP and only using ssh, I know there were problems like this on older ssh verisons but this... (0 Replies)
Discussion started by: dhlopomo
0 Replies
Login or Register to Ask a Question