[TriLUG] Basic bash shell scripting question

Matthew Todd matthew.todd at alumni.duke.edu
Thu May 29 09:30:34 EDT 2003


Hi Ryan,

I believe whoami >> checked.txt will do what you need.


But, rather than using JNI to run the shell script, you may find it
simpler to look up the username straight from your Java app, via the
system property user.name.

See System.getProperties() for the list of available properties:
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/System.html#getProperties()

Take care,
Matthew



On Thu, 2003-05-29 at 09:40, Ryan Leathers wrote:
> Hi gang. I am writing an application in Java, part of which needs to add
> the user name of a user logging onto a Linux host to a plain text list
> of user names.  (don't worry - this is not required or intended to be
> secure). The user will launch this application from their login script.
> It occurred to me that the simplest way to do this was to use JNI to
> drop to a bash shell and then mess with the file as needed in Java later
> on.  I suppose I could just launch the script independently of the Java
> app and get the same thing... but thats not really the point.
> 
> I have rarely done shell scripting over the years and am looking for
> some advice.  The lines below will do what I want, but how can I make
> this more elegant?  Can I accomplish this without creating deleting and
> renaming as seen below?   
> 
> whoami > name
> cat checked.txt name > checked.new
> rm checked.txt
> rm name
> mv checked.new checked.txt
> 
> Thanks,
> Ryan




More information about the TriLUG mailing list