LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2006, 09:00 AM   #1
symbalino
LQ Newbie
 
Registered: May 2006
Posts: 5

Rep: Reputation: 0
Unhappy script under UNIX\Linux OS


Hi!
I want to write a simple script under UNIX\Linux OS, that finds your login in /etc/passwd
and prints your login and the following 3 logins to a HTML file (named logins.html) to a table.
I Know, that its easy, but I have some problems, and I can't find the error...
If anyone can help me...
Many many many thanks in advance!
 
Old 05-25-2006, 10:17 AM   #2
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there and welcome to lq,
can you show us what you've tried so far??
regards,
slackie1000
 
Old 05-26-2006, 07:00 AM   #3
symbalino
LQ Newbie
 
Registered: May 2006
Posts: 5

Original Poster
Rep: Reputation: 0
I have this code

Hi, thank you for the help!
Until now I have this code, but I think this is not suficient

#!/bin/sh

for i in $( cat /etc/passwd);
do
$i
done
if [ whoami | grep $i)
do echo $i
fi
 
Old 05-26-2006, 03:17 PM   #4
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,
your script need some work. i will give you part of the info. afterwards you can build the script by yourself.
with grep you can reach the following...
Code:
grep -A 3 `whoami` /etc/passwd
with this you get your info, plus the next 3. you need to "clean it" before inserting in a html code.
regards,
slackie1000
 
Old 05-27-2006, 12:14 PM   #5
symbalino
LQ Newbie
 
Registered: May 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thank you for the info. This part is now working... But I want to put this information on a table. Th 1st column with the logins, teh 2nd column with the userIDs associated with the
logins in 1st column and the 3rd column with the home directories for the
logins in 1st column.
I would be gratefull if you could help me one more time. I´ll pay you a beer in Portugal or in Germany. Many thanks, Symbalino.
 
Old 05-27-2006, 12:31 PM   #6
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,
this probably the worst shell script that i ever wrote.
from the top of my head.
i am sure you can do the rest.
Code:
#!/bin/sh
myself=`whoami`
first=`grep "$myself" /etc/passwd | awk -F: '{print $1}'`
second=`grep "$myself" /etc/passwd | awk -F: '{print $3}'`
third=`grep "$myself" /etc/passwd | awk -F: '{print $6}'`
echo "<table>"
echo "<tr>"
echo "<td>"
echo "$first"
echo "</td>"
echo "<td>"
echo "$second"
echo "</td>"
echo "<td>"
echo "$third"
echo "</td>"
echo "</tr>"
echo "</table>"
exit 0
regards,
slackie1000
 
Old 05-27-2006, 12:32 PM   #7
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Note that some login information in /etc/passwd is not correct

most linux with security keep the info in another location or encrypted in this file.
 
Old 05-27-2006, 05:25 PM   #8
symbalino
LQ Newbie
 
Registered: May 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Last ask for help!

Many thank for the help, now the program is working very well!!!
But, the last thing that I need is, for example, if there is a parameter on the command line, I need that the script will print the datas for the login specified in that parameter.
Example for running the script:

1.) ./myscript -> prints the datas for your login and the following 3 logins in
/etc/passwd

2.) ./myscript xlogin25 -> the same for xlogin25

And this, really I dont Know how to do!!!
And I promess that this is My last post abou this script
 
Old 05-27-2006, 06:10 PM   #9
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Code:
#! /bin/bash

myself=$1
if [[ ! "$myself" ]]
then
    myself=$( whoami )
fi


first=... [that ugly stuff]
Now, does this also earn me a beer?
 
Old 05-27-2006, 07:02 PM   #10
symbalino
LQ Newbie
 
Registered: May 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Yes, I will pay one beer for you too!

But, only when the script is completely working,and is not the case!
I didn't understand very well, where I have to put this part of the code
 
Old 05-28-2006, 04:46 AM   #11
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,
Quote:
Originally Posted by spirit receiver
Code:
#! /bin/bash
myself=$1
if [[ ! "$myself" ]]
then
    myself=$( whoami )
fi
first=... [that ugly stuff]
Now, does this also earn me a beer?
oh. which ugly stuff you mean?
symbalino, how can you get such task if don't know some script language. we are talking here about basics. 10 s in google and you will find your answer. i gave you 90% of the information. if you want to refer the first command line parameter in your code use "$1". if you want the next three entries, you "-A 3" with grep. can you put the pieces together now?
regards,
slackie1000
 
Old 05-28-2006, 07:50 AM   #12
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
Now before you go on further, wait just ONE SECOND ! It seems to me "logins.html" is not Valid XHTML 1.0 Strict. FIX IT ! :P
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unix shell script cxy0481 Programming 9 11-20-2005 08:15 AM
Unix Book for Beginners (Not Linux... Unix) suse2166 General 6 11-25-2004 11:46 AM
UNIX (Linux, BSD, etc) Programming :: UNIX kuphryn Programming 8 04-04-2004 11:50 PM
Problem in the Unix Script triplek4ever Linux - Networking 3 10-27-2003 01:25 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 06:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration