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
groupdel(1M)						  System Administration Commands					      groupdel(1M)

NAME
groupdel - delete a group definition from the system SYNOPSIS
/usr/sbin/groupdel group DESCRIPTION
The groupdel utility deletes a group definition from the system. It deletes the appropriate entry from the /etc/group file. OPERANDS
group An existing group name to be deleted. EXIT STATUS
The following exit values are returned: 0 Success. 2 Invalid command syntax. A usage message for the groupdel command is displayed. 6 group does not exist. 10 Cannot update the /etc/group file. FILES
/etc/group system file containing group definitions ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
users(1B), groupadd(1M), groupmod(1M), logins(1M), useradd(1M), userdel(1M), usermod(1M), attributes(5) NOTES
The groupdel utility only deletes a group definition that is in the local /etc/group file. If a network nameservice such as NIS or NIS+ is being used to supplement the local /etc/group file with additional entries, groupdel cannot change information supplied by the network nameservice. SunOS 5.10 14 Sep 1992 groupdel(1M)
All times are GMT -4. The time now is 08:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy