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.
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.
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.
Thank you so much for this information. I will try this and hopefully it will work.
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]
Thanks, we have everything we need to get this going. Thanks to all who replied.