Sponsored Content
Full Discussion: Group Doesn't Exist
Homework and Emergencies Homework & Coursework Questions Group Doesn't Exist Post 302911731 by GoBoyGo on Saturday 2nd of August 2014 04:51:19 PM
Old 08-02-2014
Group Doesn't Exist

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

I'm able to create a group but when I'm trying to delete the group it keeps stating Group Doesn't Exist. I know the group exist since I created it and look at the etc/group file which is there but for some odd reason I'm unable to delete it???

2. Relevant commands, code, scripts, algorithms:
Code:
#!/usr/bin/perl

use strict;
use warnings;

my $group_name = <STDIN>;
my $group_id = <STDIN>; 
my $user_name = <STDIN>;
my $user_id = <STDIN>;
my $choice = <STDIN>;

print "* My menu *\n";
print "* *\n";
print "* 1. Create a Unix Group  *\n";
print "* 2. Delete a Unix Group  *\n";
print "* 3. Create a Unix User *\n";
print "* 4. Delete a Unix USer *\n";
print "* 5. Quit *\n";
print "* *\n";
print "******************************************************\n";
print "* Enter Your Choice >\n";

$choice = <STDIN> ;

chomp $choice;
if ($choice == 1) {
  print "**********************************\n";
  print " Create A Unix Group\n";
  print "**********************************\n";
  print " Enter The Group Name to Create >\n";
  chomp ($group_name = <STDIN>);
  print " Enter the Group ID to Create >\n";
  chomp ($group_id = <STDIN> );

  if ( ! `grep -i $group_name /etc/group` ) {
    system ("/usr/sbin/groupadd $group_id $group_name");
    print "Group Created Successfully!\n"
  } else {
    print "Group Already Exists !\n";
  }
}


elsif ($choice == 2) {
  print "**********************************\n";
  print " Delete a Unix Group\n";
  print "**********************************\n";
  print " Enter a Group Name to Delete >\n";
  chomp ($group_name = <STDIN>);
  print " Enter a Group ID to Delete >\n";
  chomp ($group_id = <STDIN> );

  if ( ! `grep -i $group_name /etc/group` ) {
    system ("/usr/sbin/groupdel -g $group_id $group_name");
    print "Delete Group Successfully!\n"
  } else {
    print "Group Doesn't Exist !\n";
  }
}

chomp $choice;
if ($choice == 3) {
  print "**********************************\n";
  print " Create a Unix User\n";
  print "**********************************\n";
  print " Enter User Name You Want to Create >\n";
  chomp ($user_name = <STDIN>);
  print " Enter the User ID >\n";
  chomp ($user_id = <STDIN>);

  if ( ! `grep -i $user_name /etc/passwd` ) {
    system ("/usr/sbin/useradd -m $user_id $user_name");
    print "Added User Successfully!\n"
  } else {
    print "User Doesn't Exist !\n";
  }
}

3. The attempts at a solution (include all code and scripts):

Tried to get some advice from stack exchange guys but no luck. I tried changing variables but that didn't help.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

CTU Online, N Chestnut St, Colorado Springs, CO 80907, Instructor Tarik Illes Course CS345

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by vbe; 08-02-2014 at 06:05 PM..
 

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
All times are GMT -4. The time now is 01:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy