Script Entry to block 9 characters userid


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Entry to block 9 characters userid
# 1  
Old 10-17-2013
Script Entry to block 9 characters userid

Hi Guys,
I have one script which is used to add new user in the system.
This is how we add new user in system:-
Code:
 sudo /opt/local/bin/new-user 114 ranivarm "Rani Varma(Libo Technical User)" INC00001111

Where
114:-is the site id
ranivarm:- is userid
"Rani Varma(Libo Technical User)" :- comment
INC00001111:- ticket number
The script is little big, so here is part of that script:-
Code:
case $steps2skip in
(help)  die "$advanced";;
(password)      steps2skip=124;;
(enable)        steps2skip=123;;
([1-4]*)        ;;
esac
username=${1:?username required: $usage} shift
ticket=$3
descr="$*"

#
# assertions
#
grep -c ${group}  /etc/group >/dev/null ||
        warn "Warning: group $group is not in /etc/group"
grep -c $shell /etc/shells >/dev/null ||
        warn "Warning: shell $shell is not in /etc/shells"
 
warn "Checking accountname ${username:?}"
if [[ $steps2skip = *1* ]]; then
        /bin/logins -xol $username ||
                die "account $username does not exist!"
        /bin/getent passwd ${username} ||
                die "account $username does not exist!"
        eval home=~${username}
else    : step 1: creating /etc/passwd entry
        /bin/getent passwd ${username} &&
                die "account $username already exists!"
        /bin/logins -xol $username

Could you please tell me what entry should I enter and where should I insert it?
Thanks
# 2  
Old 10-17-2013
Telling us what you mean by 'block' and which 9 characters would be a start...
This User Gave Thanks to CarloM For This Post:
# 3  
Old 10-17-2013
I mean

Code:
sudo /opt/local/bin/new-user 114 ranivarm "Rani Varma(Libo Technical User)" INC00001111

should work

and this

Code:
sudo /opt/local/bin/new-user 114 ranivarma "Rani Varma(Libo Technical User)" INC00001111

should through error message as can not create userid as it has 9 characters ranivarma.

block means should throw an error message and userid should not be created.

Thanks
# 4  
Old 10-17-2013
You can check the length of a string using ${#VAR}

e.g.
Code:
[ ${#username} -le 8 ] || die "Some error"


Last edited by CarloM; 10-17-2013 at 12:56 PM.. Reason: Typo
This User Gave Thanks to CarloM For This Post:
# 5  
Old 10-17-2013
Quote:
Originally Posted by CarloM
You can check the length of a string using ${#VAR}

e.g.
Code:
[ ${#username} -le 8] || die "Some error"

Yes, thanks but where to insert this code as my script looks too complicated for me to understand.
# 6  
Old 10-17-2013
Quote:
Originally Posted by manalisharmabe
Yes, thanks but where to insert this code [ ${#username} -le 8] || die "Some error" as my script looks too complicated for me to understand.
If this looks too complicated to you, i wonder how you could achieve this line in the first place..
Code:
username=${1:?username required: $usage} shift

But anyway...
Its just below that...

Last edited by sea; 10-17-2013 at 10:42 AM..
This User Gave Thanks to sea For This Post:
# 7  
Old 10-17-2013
Quote:
Originally Posted by sea
If this looks too complicated to you, i wonder how you could achieve this line in the first place..
Code:
username=${1:?username required: $usage} shift

But anyway...
Its just below that...
This script is created by someone in 2005, I am not that good in scripting, I understand only small-medium scripts.
let me try your lines.

Thanks a lot!

Edit:- You have almost helped me, but I am getting below syntax error:-
Code:
-bash-3.2$ /usr/local/bin/sudo /opt/local/bin/new-user 199  testuser1 "test user (Script testing User)" INC000017310
/opt/local/bin/new-user[124]: test: ] missing
username should not more than 8 characters
-bash-3.2$

here is what script has:-
Code:
80  while getopts b:f:g:s:u:X: c; do
    81  case $c in
    82  (b)     basedir=${OPTARG}       # directory
    83          case $basedir in        # or numeric site code
    84          ( +([0-9]) )
    85                  basedir=$( print /users/*/$basedir )
    86                  [[ -d $basedir ]] || die "no such directory: $basedir"
    87          esac
    88          # kept -b option for backwards compatibility
    89          ;;
    90  (f)     for profile in ${OPTARG} ${OPTARG}/.profile; do
    91                  # we accept either a directory with a .profile, or a full path to the file
    92                  [[ -f $profile ]] && break
    93          done || die ".profile expected: $usage"
    94          ;;
    95  (g)     group=${OPTARG:?$usage};;
    96  (s)     shell=${OPTARG};;
    97  (X)     steps2skip=${OPTARG} ;;
    98  esac
    99  done
   100  shift $((OPTIND - 1 ))
   101
   102  #
   103  # Replaces -b option: "-b" is actually redundant, as long as
   104  # arg1 is either nnn or /path/name.
   105  #
   106  # numeric $1 == basedir
   107  if [[ $1 = @([0-9][0-9][0-9]|/*) ]]; then
   108          basedir=$1 shift
   109          case $basedir in        # or numeric site code
   110          ( +([0-9]) )
   111                  basedir=$( print /users/*/$basedir )
   112                  [[ -d $basedir ]] || die "no such directory: $basedir"
   113          esac
   114  fi
   115
   116  case $steps2skip in
   117  (help)  die "$advanced";;
   118  (password)      steps2skip=124;;
   119  (enable)        steps2skip=123;;
   120  ([1-4]*)        ;;
   121  esac
   122
   123  username=${1:?username required: $usage} shift
   124  [ ${#username} -le 8] || die "username should not more than 8 characters"
   125  ticket=$3
   126  descr="$*"
   127
   128
   129  #
   130  # assertions
   131  #
   132
   133  grep -c ${group}  /etc/group >/dev/null ||
   134          warn "Warning: group $group is not in /etc/group"
   135
   136  grep -c $shell /etc/shells >/dev/null ||
   137          warn "Warning: shell $shell is not in /etc/shells"
   138
   139
   140
   141  warn "Checking accountname ${username:?}"
   142
   143  if [[ $steps2skip = *1* ]]; then
   144
   145          /bin/logins -xol $username ||
   146                  die "account $username does not exist!"
   147          /bin/getent passwd ${username} ||
   148                  die "account $username does not exist!"
   149
   150          eval home=~${username}
   151
   152  else    : step 1: creating /etc/passwd entry
   153
   154          /bin/getent passwd ${username} &&

It is showing sysntax error, I tried to put two [[ and ]] but got same error. the line 124 needs some entry I guess.
Please advise.

Last edited by manalisharmabe; 10-17-2013 at 01:30 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cron entry to pass the value to script

0 I have a script(main.sh) which calls another script(Get_Files.sh) and gets a value in a variable like the below: File_to_Refresh="$(sh /Aug/work/Get_Files.sh /Aug/Work/Universal_File.txt)" Now I have to schedule the script main.sh for 3 different files i.e. the Universal_File.txt with 3... (2 Replies)
Discussion started by: bhartiya007
2 Replies

2. Shell Programming and Scripting

How to replace multiple "&nbsp;" entry with in <td> tag into single entry using sed?

I have the input file like this. Input file: 12.txt 1) There are one or more than one <tr> tags in same line. 2) Some tr tags may have one <td> or more tna one <td> tags within it. 3) Few <td> tags having "<td> &nbsp; </td>". Few having more than one "&nbsp;" entry in it. <tr> some td... (4 Replies)
Discussion started by: thomasraj87
4 Replies

3. Shell Programming and Scripting

awk script to call another script based on second column entry

Hi I have a text file (Input.txt) with two column entries separated by tab as given below: aaa str1 bbb str2 cccccc str3 dddd str4 eee str3 ssss str2 sdf str3 hhh str1 fff str2 ccc str3 ..... ..... ..... (1 Reply)
Discussion started by: my_Perl
1 Replies

4. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

5. Shell Programming and Scripting

Automatic su password entry script

Before I start, two things. 1) Yes I know it's bad practice and obomination to all things holy, but I'm not a sys admin at JP Morgan, I'm a hobbyist tooling about in a VM, in my pants, at home. 2) If you are just going to flame for even considering hardcoding a root password, thanks, I get... (2 Replies)
Discussion started by: 3therk1ll
2 Replies

6. Shell Programming and Scripting

mapping userid to an email in script

i have about 20 different users submitting a web form that executes a unix script in the background that sets EXECUTIONUSER to their unix id. i would like to use $EXECUTIONUSER to set their email address as EMAILADDR. of course their unix id does not match their email name either. for example: ... (3 Replies)
Discussion started by: crimso
3 Replies

7. Shell Programming and Scripting

FTP automation with special characters in userid

Hi, i am trying to automate an ftp script which is as below.But my user id has special characters(aaa\$ifg). So it is not working correctly.Can anyone help on this?I tried providing both of them in double & singe quoted. But somehow it is not picking the "\". Also tried keeping \ before the... (3 Replies)
Discussion started by: aeroticman
3 Replies

8. Solaris

How do I configure sendmail to block all OUTGOING mail FROM one userid TO the world?

Hello, ENVIRONMENT: OS: Solaris 10 Sendmail: 8.13.8+Sun BACKGROUND: We had a user account that was compromised and was used as a relay. She sent out (or would have if we didn't kill sendmail) ~10K emails alerting people they just won $75K. The target for this spam was everyone internal... (1 Reply)
Discussion started by: avikb
1 Replies

9. Shell Programming and Scripting

Script to find systems logged in with a particular userid

Hello All, I need to design a script to get all the systems names(IP Addresses) logged in with a particular userid say 'xyz' from different terminals. This is to track the use of the particular userid and take action if it is being misused. The script would accomplish the following steps: 1.... (1 Reply)
Discussion started by: mehimadri
1 Replies

10. Shell Programming and Scripting

Script for data entry

Hello everyone. I just registered like 17 minutes ago and am new to UNIX/Linux. I work in a small department of an animation company that does compositing tricks to fix movie frames. After our work is completed we are tasked with creating a text log that has information on what work we had... (7 Replies)
Discussion started by: AndrewP
7 Replies
Login or Register to Ask a Question