LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   script under UNIX\Linux OS (http://www.linuxquestions.org/questions/programming-9/script-under-unix%5Clinux-os-448414/)

symbalino 05-25-2006 09:00 AM

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!

slackie1000 05-25-2006 10:17 AM

hi there and welcome to lq,
can you show us what you've tried so far??
regards,
slackie1000

symbalino 05-26-2006 07:00 AM

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

#!/bin/sh

for i in $( cat /etc/passwd);
do
$i
done
if [ whoami | grep $i)
do echo $i
fi

slackie1000 05-26-2006 03:17 PM

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

symbalino 05-27-2006 12:14 PM

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.

slackie1000 05-27-2006 12:31 PM

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

exvor 05-27-2006 12:32 PM

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.

symbalino 05-27-2006 05:25 PM

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!!!:scratch:
And I promess that this is My last post abou this script ;)

spirit receiver 05-27-2006 06:10 PM

Code:

#! /bin/bash

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


first=... [that ugly stuff]

Now, does this also earn me a beer?

symbalino 05-27-2006 07:02 PM

Yes, I will pay one beer for you too!
 
But, only when the script is completely working,and is not the case!:confused:
I didn't understand very well, where I have to put this part of the code:eek:

slackie1000 05-28-2006 04:46 AM

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? :cool:
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

introuble 05-28-2006 07:50 AM

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 :)


All times are GMT -5. The time now is 09:32 AM.