Sponsored Content
Top Forums Shell Programming and Scripting Help with simple program. (beginner) Post 302513964 by Corona688 on Thursday 14th of April 2011 12:04:35 PM
Old 04-14-2011
A good start but there's a few things to figure out here:
Code:
if [ $ cat /etc/passwd | cut -d: -f1= "$username" ]

You don't put programs inside [ ] like that, you can just put them there raw.

That is also a useless use of cat, whenever you have cat stuff | program it's better to do program < stuff.

There's a trick you can do with grep to check for a user in the password file:

Code:
if grep -q "^${username}:" /etc/passwd
then
...

The ^ makes it look at the beginning of the line, so it looks for ${username}: at the beginning of any line in /etc/passwd. The -q tells it not to print anything, just return true or false as usual.

Code:
while [ $(who | grep $username) != 0 ]

This is a useless use of backticks (since the $(stuff) syntax is a special form of backticks). You don't check a return value in that fashion, either -- what that statement would actually end up doing is checking the string output of who | grep $username.

How you check a return value is like:

Code:
# there really are 'true' and 'false' programs, so go ahead and
# try these statements
if true
then
       echo "true returns true"
fi

if ! false
then
        echo "false returns false"
fi

So how about:
Code:
while who | grep -q "${username}"
do
...

Code:
exit 1

1 means error, by returning 1 you're telling whatever ran it that your program failed. Use 'exit 0' to show that your program ran successfully.
 

10 More Discussions You Might Find Interesting

1. Programming

QUESTION...simple program?

I am new to the unix/linux environment. AND........ I need to create a mini shell..that displays prompt (i.e., READY:$), accepts a command from std-in, and prints the command and any parameters passed to it. HELP!!!! (8 Replies)
Discussion started by: jj1814
8 Replies

2. Programming

a simple chat program

any suggestions on how i could create a simple chat program between two terminals using pipes? thanks (1 Reply)
Discussion started by: kelogs1347
1 Replies

3. UNIX for Dummies Questions & Answers

A beginner for cygwin simple question

the current pwd is: c:\cygwin\home\hui which command can go to c:\documents and setting\hui\my documents\hui\reply.txt (1 Reply)
Discussion started by: zhshqzyc
1 Replies

4. Programming

Xlib simple program.

I don't know if it is right to ask you this. Can someone help me write a simple Xlib program,with button on it,and all that button do is switch 2 messages. I have tried and tried,but never get past Hello World. Can someone help me please? ---------- Post updated at 10:17 PM ---------- Previous... (2 Replies)
Discussion started by: megane16v
2 Replies

5. Shell Programming and Scripting

simple program help required

The circumfrence of a circle is #!/usr/bin/perl print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654 # r= 12.50 I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
Discussion started by: Q2wert
3 Replies

6. UNIX for Dummies Questions & Answers

Installing a Program called MAQ (Beginner Here)

Basically, I'm trying to install this program called MAQ. Maq User's Manual I've downloaded it and I tried to type in $ ./configure; make; make install but the ouput I got was this: bash: ./configure: No such file or directory make: Entering directory `/home/vlay/bwa-0.5.0' make:... (8 Replies)
Discussion started by: vlay2
8 Replies

7. Shell Programming and Scripting

very simple but mount everest for beginner

List directories at the home directory in increasing order. First of all is this correct? cd ~/ du -h|sort -n|more First command is to go to the home directory and second does the rest. Is there a way to do them in single command. Thanks in advance. (1 Reply)
Discussion started by: kevincobain2000
1 Replies

8. UNIX for Dummies Questions & Answers

Help with creating a simple program!!

i am new to shell scripting!! i am making this program in bourne shell, that asks the user to input "Hello (their name)" or "question (their name)", any other input, "ERROR" will be outputted. if they input "Hello (name)", i want to out saying Hello (name) but if they input "question (name)", i... (4 Replies)
Discussion started by: bshell_1214
4 Replies

9. Programming

A simple C program query ...

Given the following code inside the function ext3_write_super(): (It's there in Linux kernel 2.6.27.59) static void ext3_write_super (struct super_block * sb) { if (mutex_trylock(&sb->s_lock) != 0) BUG(); sb->s_dirt = 0; } The conditional test at if... (2 Replies)
Discussion started by: Praveen_218
2 Replies

10. Shell Programming and Scripting

Help/How-to - simple UNIX script / gzip (beginner)

Hey all, I would like to ask your help and sorry in advance for my ignorance since I am a complete beginner in this. I need to create a UNIX script that will: - scan a small number of folders and subfolders (see a similar file tree in the attachment) - - for each final folder (each of... (8 Replies)
Discussion started by: McNulty
8 Replies
asadmin-list-file-groups(1AS)					   User Commands				     asadmin-list-file-groups(1AS)

NAME
asadmin-list-file-groups, list-file-groups - lists the file groups SYNOPSIS
list-file-groups --user admin_user [--password admin_password] [--host localhost] [--port 4848] [--secure|-s] [--passwordfile filename] [--terse=false] [--echo=false] [--interactive=true] [--authrealmname auth_realm_name] [--name username] Lists the available groups in the file user. If the name option is not specified, then all groups are listed. This command is supported in remote mode only. OPTIONS
--user authorized domain application server administrative username. --password password to administer the domain application server. --host machine name where the domain application server is running. --port port number of the domain application server listening for administration requests. --secure if true, uses SSL/TLS to communicate with the domain application server. --passwordfile file containing the domain application server password. --terse indicates that any output data must be very concise, typically avoiding human-friendly sentences and favoring well- formatted data for consumption by a script. Default is false. --echo setting to true will echo the command line statement on the standard output. Default is false. --interactive if set to true (default), only the required password options are prompted. --authrealmname filename where you have different stores for file auth realm. --name name of the file user. Example 1: Using the list-file-groups command asadmin> list-file-groups --user admin1 --password adminadmin1 --host pigeon --port 5001 --name sample_user Command list-file-groups executed successfully EXIT STATUS
0 command executed successfully 1 error in executing the command asadmin-delete-file-user(1AS), asadmin-update-file-user(1AS), asadmin-create-file-user(1AS), asadmin-list-file-users(1AS) J2EE 1.4 SDK March 2004 asadmin-list-file-groups(1AS)
All times are GMT -4. The time now is 09:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy