Sponsored Content
Full Discussion: Group Doesn't Exist
Homework and Emergencies Homework & Coursework Questions Group Doesn't Exist Post 302912072 by junior-helper on Tuesday 5th of August 2014 01:55:50 PM
Old 08-05-2014
Bug

Hi dude,
the actual problem is the wrong "if"-statement, one line before the "groupdel" command.
Due to the exclamation mark, it reads like "If the group ... is NOT found, delete it",
but since the group does exist, the else part of that if statement gets triggered.
So you got to remove the exclamation mark (!) in the line 53.

I guess that happened because you copied it from the groupadd section.

Here are some further suggestions:

1. imho you don't need to read from STDIN at the program start, so try this instead:
Code:
my ($group_name, $group_id, $user_name, $user_id, $choice);

2. There is a "-g" option missing between the groupadd command and $group_id

3. groupdel requires groupname as argument, so probably you should remove -g $group_id (see jim's answer)

4. you should not simply system("some-command") and then independently print some status or return code. Try this:
Code:
system ("/usr/sbin/groupadd -g $group_id $group_name && echo 'Success!' || echo 'Error!'");

5. if ($choice == 1) ... elsif ($choice == 2) ... if ($choice == 3) seems not to be consistent

6. If your perl script still misbehaves, consider using the perl debugger: perl -d yourscript.pl

HTH, good luck!
This User Gave Thanks to junior-helper For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What hapens if a group member doesn't exist?

As part of a NIS implementation, (I think) I want to create a group (in /etc/group) that has users that do not exist on the target machine. What effect will this have? Will it cause any problems? Thanks, Gary Cooper (1 Reply)
Discussion started by: Gary Cooper
1 Replies

2. UNIX for Advanced & Expert Users

Validate if user and group exist

I'm kinda new to unix programming so bear with me... I'm running a script prompting a user for an existing user and group and want to be able to validate if they valid. Is there any code available? Any help or push in the right direction would help. Thank you, (2 Replies)
Discussion started by: thedon
2 Replies

3. Shell Programming and Scripting

sftp mget where file doesn't exist BASH

I have a script that is working: #!/bin/bash sftp user@domain.com <<EOF cd somedir mget *.csv quit EOF but on a crontab I want to only pull newer files, so I want to do something like: while read ls current dir local file != true do mget that new file but I'm not sure the syntax... (2 Replies)
Discussion started by: unclecameron
2 Replies

4. Shell Programming and Scripting

Group Exist Scripting

Hey People, I've got a question! How can i write a function in a script which is looking for if a group exist and if not, that the group "users" is the standard group..I know that i have to use "grep" und "if-else"..I will be very happy for answers ;) Greetz Ali (2 Replies)
Discussion started by: AliC
2 Replies

5. Shell Programming and Scripting

Perl: One action if an element doesn't exist in array

Hello, I want to run one (not multiple) action if an element doesn't exist in array. for example: @array = (1..10); foreach $el (@array) { if ($el != 11) { print "number not found\n"; } } the output of this simple script: number not found (3 Replies)
Discussion started by: ahmed_zaher
3 Replies

6. Programming

Kernel module - How to test if file doesn't exist

Hey, I'm currently getting into some kernel module progamming. As a little exercise I want to read the headers out of an ELF file. My code is very simple, here is the important part: struct file *fp; /* ... */ fp = filp_open("some/file/on/my/pc", O_RDONLY, 0); if(fp == NULL) { ... (15 Replies)
Discussion started by: disaster
15 Replies

7. UNIX for Dummies Questions & Answers

Removing a user that doesnt exist from a group

Hi there, normally if I want to remove a user tht I have added to a specific group, i would do the following this is what my group2 looks like # grep group2 /etc/group group2:x:7777:user2,user1,user4 user1 has been defined in a few groups # id -nG user1 group1 group2 group3 So... (3 Replies)
Discussion started by: rethink
3 Replies

8. Solaris

User directory doesn't exist

Hii all, i create the user useradd -d /home/kk kk passwd kk when i tried to login to kk i get a error user directory doesn't exist then i tried useradd kkk passwd kkkwhen i tried to login to kkk i get the same error user directory doesn't exist. (4 Replies)
Discussion started by: vipinkumarr89
4 Replies

9. Red Hat

Removing LVM Volume Group that doesn't exist anymore

Our SAN administrator decided to unpresent then destroy LUN's we were actively using as a volume group (all PV's in said volume group). Now every time I do a pvscan or whatever it complains about I/O errors trying to access those PV's. How do I get it to forget the VG existed completely? vgreduce... (7 Replies)
Discussion started by: thmnetwork
7 Replies

10. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies
MKTEMP(P)						     POSIX Programmer's Manual							 MKTEMP(P)

NAME
mktemp - make a unique filename (LEGACY) SYNOPSIS
#include <stdlib.h> char *mktemp(char *template); DESCRIPTION
The mktemp() function shall replace the contents of the string pointed to by template by a unique filename and return template. The appli- cation shall initialize template to be a filename with six trailing 'X' s; mktemp() shall replace each 'X' with a single byte character from the portable filename character set. RETURN VALUE
The mktemp() function shall return the pointer template. If a unique name cannot be created, template shall point to a null string. ERRORS
No errors are defined. The following sections are informative. EXAMPLES
Generating a Filename The following example replaces the contents of the "template" string with a 10-character filename beginning with the characters "file" and returns a pointer to the "template" string that contains the new filename. #include <stdlib.h> ... char *template = "/tmp/fileXXXXXX"; char *ptr; ptr = mktemp(template); APPLICATION USAGE
Between the time a pathname is created and the file opened, it is possible for some other process to create a file with the same name. The mkstemp() function avoids this problem and is preferred over this function. RATIONALE
None. FUTURE DIRECTIONS
This function may be withdrawn in a future version. SEE ALSO
mkstemp() , tmpfile() , tmpnam() , the Base Definitions volume of IEEE Std 1003.1-2001, <stdlib.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 MKTEMP(P)
All times are GMT -4. The time now is 06:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy