Results 1 to 10 of 10

Thread: Check for users and exclude them from a later function

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Check for users and exclude them from a later function

    I"m trying to figure out the best way to do this and I think it would be an IF statement. I have 2 users "user1" and "user2" that I need to make sure get excluded from a certain process so in my mind it would look something like

    IF $user1 = (array of exlcuded users) then quit
    else if
    do
    other process.

    That's a rough idea of how I think it would look. Are there better ways than a simple IF statement for this?

    Thanks,

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    hi,

    using case is probably better.
    «A problem clearly stated is a problem half solved.»

  3. The Following User Says Thank You to Watael For This Useful Post:

    mosiac (6th December 2012)

  4. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Yeah that's a good idea in case I have multiple situations arise later as opposed to constant nested if statements. Thanks.

  5. #4
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Hi,

    another way is using grep , i knew , some one will be say why call external program ,

    PHP Code:
    #!/bin/bash

    exclude_array=( user1 user2 user3 )

    read -"Enter Username to search in Exclude List :- " input_user

    if echo "${exclude_array[@]}grep -"${input_user}"then

            
    echo "${input_user} is in exlude list"

    else
            echo 
    "${input_user} is not in exlude list"
    fi 
    Testing:
    Code:
    [root@db1 ~]# bash  /tmp/test.sh
    Enter Username to search in Exclude List :- user1
    user1 is in exlude list
    [root@db1 ~]# bash  /tmp/test.sh
    Enter Username to search in Exclude List :- user5
    user5 is not in exlude list
    Rahul Patil <http://www.linuxian.com>

  6. #5
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    why call external program
    yes, why!?

    using bash:
    Code:
    $ exclude_array=( user1 user2 user3 )
    $ oIFS="$IFS"
    $ IFS='|'
    $ list="${exclude_array[*]}"
    $ IFS="$oIFS"
    $ [[ user4 = @($list) ]] && echo ok || echo ko
    ko
    $ [[ user1 = @($list) ]] && echo ok || echo ko
    ok
    see man bash /Pattern Matching
    no need to set extglob on, because the test happens between [[ ]]
    «A problem clearly stated is a problem half solved.»

  7. #6
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Hi Watael,

    Can you please explain "@($list)"
    Rahul Patil <http://www.linuxian.com>

  8. #7
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    I gave the man page and paragraph where to find the infos.
    @(pattern-list)
    Matches one of the given patterns
    works without extglob set for [[, but not for case (for which extglob has to be set using shopt)
    «A problem clearly stated is a problem half solved.»

  9. #8
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    I see the idea, but I'm looking for more of an automation script, somthing that will be placed in /etc/profile and run everytime a user logs in. The idea is to automate some of the day to day processes I have to do for new users that I'd like to not have to do anymore.

    Thanks for the suggestions though

  10. #9
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    what's the problem with putting such code in /etc/profile?
    «A problem clearly stated is a problem half solved.»

  11. #10
    Junior Member
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by Watael View Post
    what's the problem with putting such code in /etc/profile?
    Well mainly Rahul's code is the only one that requires input is all. The others will work fine

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 30th November 2012, 12:14 PM
  2. tar command with exclude parameter
    By indianboy in forum Shell scripting
    Replies: 1
    Last Post: 25th April 2012, 11:48 PM
  3. How to configure a exclude range in DHCP pool.
    By vamshikrishna.g7 in forum Ubuntu / Debian
    Replies: 0
    Last Post: 6th April 2011, 12:13 PM
  4. Call Function Within Function [PHP]
    By eawedat in forum Coding in General
    Replies: 1
    Last Post: 4th June 2010, 09:08 PM
  5. diff command to exclude files that match pattern
    By piggy in forum Getting started tutorials
    Replies: 1
    Last Post: 13th August 2007, 10:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41