program or script to display user info


 
Thread Tools Search this Thread
Top Forums Programming program or script to display user info
# 1  
Old 01-06-2009
Bug program or script to display user info

I'm on a Linux machine and need a program that will display user information as follows: user name, user directory and current date & time.
I think we can compile C, C++ and Perl.
All help is appreciated.
# 2  
Old 01-06-2009
PHP

You can do this in perl.

You should start by looking at the values contained in the %ENV function.

The following (once inserted into a perl script and run) will display the environment variables in the %ENV hash.

Code:
foreach $vn(sort keys %ENV) {
 printf "%-15.15s %-50.50s\n",
 $vn,$ENV{$vn};
 }


$ENV{"USER_NAME"} and $ENV{"HOME"} will be a place to start.



For the date, you should look over the localtime function in perl.
Search the perl/unix/whatever forums here for perl localtime and you will find a wealth of information.
# 3  
Old 01-06-2009
Thank you so much for this information. I will try this and hopefully it will work.
Smilie
# 4  
Old 01-06-2009
If you wish your code to work with other usernames/uids other than the current user's:

perl -e 'print "".(getpwuid($<))[0]." ".(getpwuid($<))[7]."\n";'

You can also use getpwnam() if you wish to use a username instead of a UID.
$< is the real UID of the current process, but you could change it according to what you need ... (getpwuid(YOUR_UID))[0]
# 5  
Old 01-07-2009
Thanks, we have everything we need to get this going. Thanks to all who replied.

Last edited by flasun; 01-07-2009 at 10:39 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exit script and open program via other user

Hello all.. so i have a problem i need to solve .. #! /bin/bash $SHELL dtterm -title my_prog -e su -user -c 'export DISPLAY=:0.0 ; /path/to/my/prog' & 2> /dev/null $SHELL intr exit This script will work on solaris 10 system in right clikt menu - in a secure system so i need to... (0 Replies)
Discussion started by: defs
0 Replies

2. Shell Programming and Scripting

Bash Info Display

I have written the following bash function prArgv Suppose the calling sequence is as follows prArgv VAL1 VAL2 DESC VAL3 VAL4 v2d1 s4 p15 The call will look at the tag k1v2, add the numbers together, in this case 2+1=3 This means that the function will look at the first 3 user arguments... (1 Reply)
Discussion started by: kristinu
1 Replies

3. Shell Programming and Scripting

Shell script to display user logged last week and time connected

Hello all, I want to display all the user logged last week and know the time tnat they are connected. I have been looking for a solution in the Forum, but I didn't find. Thanks in advance (4 Replies)
Discussion started by: ahernandez
4 Replies

4. Shell Programming and Scripting

Run a bash script, display on the screen and save all information in a file including error info

Hi all, How to: Run a bash script, display on the screen and save all information in a file including error information. For example: I have a bash script called test.sh now I want to run the test.sh and display the output on the screen and save the output including error info to a file. ... (1 Reply)
Discussion started by: Damon sine
1 Replies

5. UNIX Desktop Questions & Answers

Shell script to display user logged in within given time

how can i know which users have logged in at specified given start and end time in 24 hour format? (3 Replies)
Discussion started by: meherzad4u
3 Replies

6. Shell Programming and Scripting

Update LDIF User info based on Test User Certs ID's

Hi I need help.......... I have an Sun One Directory server LDIF file with 5000 user entries, I need to change the data to match Test ID's, so I can run a perf test. I'm way out of my league as I have not done any scripting for 10 years. There are four entries for each user in the file... (3 Replies)
Discussion started by: Macdaddy99
3 Replies

7. Shell Programming and Scripting

Executing program with Perl script but needs user input

Hello, I'm running a perl script to execute a program through my Unix command line. The program requires a user input but I want to automatically have perl input the string. Is there a way to do this? Thanks (1 Reply)
Discussion started by: leonard2352
1 Replies

8. Programming

Getting process info in a program

Hi, I am wondering if there is a way to find out in a C software program if a particular process is running without having to write a file. In the past, I have been using the system command to execute a pgrep and output the info to a file. Then the C program reads the file to make the... (1 Reply)
Discussion started by: herbmiller
1 Replies

9. Shell Programming and Scripting

possible to run script to enter info within a program?

hi, I am new to Unix and script writing so I was wondering if this would be possible and how I might do it. I've learned to write a basic script and the first step I need to do is to open a program (for genetic linkage). The program then requires me to enter a lot of information. Sort of line... (1 Reply)
Discussion started by: lianderthal
1 Replies
Login or Register to Ask a Question