Tag Archives: EOF

Bash conditional | getting logic wrong?

By the_gripmaster

I have a file

Code:

cat < /tmp/test
Line one
Line two
Line three
EOF


Now I am trying to get the exit stat ($?) of 1 if any text is found and 0 if any text is not found using grep, i.e. just reversing the exit status of grep

Code:

# (snippet 1) this one is not working!!! retval $? should be 1
grep -q 'one' /tmp/test && false || true
echo $?

# (snippet 2) but this one is working - retval is 1
grep -q 'one' /tmp/test
if [ $? -eq 0 ]; then
false
else
true
fi
echo $?


What am I missing in snippet 1?

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Expect Script – Variables are Empty immediately after "Setting" Them?

By mrm5102

Hello All,

I have embedded some expect code inside a Bash script I’m writing, but for some reason any variable I ‘set’ to something is
showing as empty immediately on the next line…

I haven’t run into this problem before so I’m not sure what it could be…? I’m guessing it has something to do with the code
being embedded in another script..?

Here’s my Code:

Code:

#!/bin/bash

echo "Here, in Bash Script"

# other stuff.....:......

/usr/bin/expect - << EOF

set my_var "Hello World"

puts "my_var = $my_varn"

EOF

echo "Back from Expect Script"

exit 0


And my Output:

Code:

Here, in Bash Script
my_var =

Back from Expect Script


Anyone know why the variables are NOT being set? I’m Stumpped..!!!
Any thoughts would be very much appreciated.

Thanks in Advance,
Matt

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Script not working

By mohtashims

Code:

echo "Generating ApplicationStatus.py"
OUTFILE=moht1.txt
(
cat <<EOF
#!/bin/bash
print '####### Application ####### Application Staten'
exit 0
EOF
) > /tmp/$OUTFILE
echo "ApplicationStatus.py generated successfully"
echo "Generating ServerStatus.py ..."
OUTFILE=moht2.txt
(
cat <<EOF
#!/bin/bash
print '##### Server Health State #####', server.getHealthState()
exit 0
EOF
) > /tmp/$OUTFILE
echo "ServerStatus.py generated successfully"


I get the below error:

Quote:

./makefiles.sh: line 21: syntax error: unexpected end of file


…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

How to setup Oracle connection inside shell script?

By sandy162

Hi,

We have Oracle Connection parameters set up in file name “TESTDB” at location /abc/etc.When I try to run my shell script it does not connect to Oracle database. Please let me know how “TESTDB” file can be called inside script.

Code:

####################### Setting the directories #############################
CFG_DIR=/abc/etc/TESTDB
#################################################################################
#------Truncate the base table before loading today's data -------#

${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} <> ${LOG_FILE} 2>&1
set serveroutput on;
TRUNCATE TABLE TBL_STG_LOAD;
COMMIT;
QUIT;
EOF


To run the script $ > . ./scriptname.sh

Thanks
Sandy

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

$ symbol in sql query in shell script

By indira_s

Hi Team,

Can you please help me to resolve this issue.

Am unable to use this $ symbol in sql query in the shell script.

For Example:

# !/bin/sh

export USER_NAME=XXX
export PASSWORD=YYY

export ORACLE_SID=xamdb
echo $ORACLE_SID

echo ” Session Details …”

DATE_TIME=`date +%Y%m%d_%H%M%S`
echo $DATE_TIME

#`$ORACLE_HOME/bin/
sqlplus $USER_NAME/$PASSWORD@xamdb << EOF
set serveroutput on
set feedback off

SELECT count(1) AS con_count, machine, username , osuser, status
FROM v$session
WHERE type ‘BACKGROUND’
GROUP BY username, machine ,osuser, status
ORDER BY con_count DESC;

END;
/
EOF

echo “Completed Session details…”

Output:
======
SQL> SQL> SQL> SQL> SQL> 2 3 4 5 FROM v
*
ERROR at line 2:
ORA-00942: table or view does not exist

SQL> SQL> SP2-0042: unknown command “END” – rest of line ignored.
SQL> FROM v
*
ERROR at line 2:
ORA-00942: table or view does not exist

———- Post updated at 05:22 PM ———- Previous update was at 05:11 PM ———-

I got the answer. we should use symbol.
SELECT count(1) AS con_count, machine, username , osuser, status
FROM v$session
WHERE type ‘BACKGROUND’
GROUP BY username, machine ,osuser, status
ORDER BY con_count DESC;

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

How to generate HTML page from UNIX script out-put?

By HHarsh

Hi All.

This my first post to this forum, and i assuming it will be best out-of all.

I am quite new to Unix scripting so please excuse me for any silly questions –

I am trying to create on Unix script in which it telnet to my server, check the connectivity of the server and then it generate the out-put.

I am getting correct output and everything is fine.

Now i want to extend that to some extend –

Now i want to the output of the script i should get in HTML formats in email.

conct_asap () {
cd ${home}
telnet 10.97.111.111 40003 >tap <<EOF
^]
quit
EOF
}
conct_asap 2>asap.log 1>asap.log

grep “Connected” ${home}/asap 2>/dev/null 1>/dev/null
clear
if [ $? -eq 0 ];then
echo “1]. ${bold}ASAP Check${unbold}”
echo “_________________________________”
echo “Connectivity –> UP and Running”
———————————————————————–
So will it possible to generate HTML out-put and send to my mail box ?:wall:

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

awk with variable from sqlplus

By jonathanb30

Hi, I’m a it stuck on the below code where a variable is pulled from sqlplus and used in awk. It runs with no errors but still pulls back all records in the input file.

It should pull the max reference from sql plus and then only print those records where the reference value in column 1 is greater than the max reference value from the db.

Input file is a comma delimited and reference is a 14 digit number.

Thanks for any help in pointing me in the right direction!


value=`sqlplus -s user/pass << EOF
set heading off;
select max(reference) from cred_table;
exit;
EOF`

awk -F "," -v ref=$value'{if ($1 >= ref) printf("%-16s%-20s%-50s%-20s%-60s%-12s%-9s%-20s%-20s%-20s%-30s%-20s%-20s%-20s%-20s%-50s%-20s%-50s%-20s%-20s%-100s%-4s%-4s%-20s%-20s%-10s%-10s%-10s%-25s%-25s%-100s%-40s%-20s%-20s%-40s%-20s%-20s%-25s%-3s%-10s%-10s%-20s%-10s%-1s%-10s%-4s%-4s%-4s%-4s%-3s%-4s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10sn",$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,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$60,$61)}' appfile_$Day.out > C_LIQ_CR_APP_RT_$Day.DAT


…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Martin Pitt: umockdev 0.2: record/replay input devices

I just released umockdev 0.2.

The big new feature of this release is support for evdev ioctls. I. e. you can now record what e. g. X.org is doing to touchpads, touch screens, etc.:

  $ umockdev-record /dev/input/event15 > /tmp/touchpad.umockdev
  # umockdev-record -i /tmp/touchpad.ioctl /dev/input/event15 -- Xorg -logfile /dev/null

and load that back into a testbed with X.org using the dummy driver:

  cat <<EOF > xorg-dummy.conf
  Section "Device"
        Identifier "test"
        Driver "dummy"
  EndSection
  EOF

  $ umockdev-run -l /tmp/touchpad.umockdev -i /dev/input/event15=/tmp/touchpad.ioctl -- Xorg -config xorg-dummy.conf -logfile /tmp/X.log :5

Then e. g. DISPLAY=:5 xinput will recognize the simulated device. Note that Xvfb won’t work as that does not use udev for device discovery, but only adds the XTest virtual devices and nothing else, so you need to use the real X.org with the dummy driver to run this as a normal user.

This enables easier debugging of new kinds of input devices, as well as writing tests for handling multiple touchscreens/monitors, integration tests of Wacom devices, and so on.

This release now also works with older automakes and Vala 0.16, so that you can use this from Ubuntu 12.04 LTS. The daily PPA now also has packages for that.

Attention: This version does not work any more with recorded ioctl files from version 0.1.

More detailled list of changes:

  • umockdev-run: Fix running of child program to keep stdin.
  • preload: Fix resolution of “/dev” and “/sys”
  • ioctl_tree: Fix endless loop when the first encountered ioctl was unknown
  • preload: Support opening a /dev node multiple times for ioctl emulation (issue #3)
  • Fix parallel build (issue #2)
  • Support xz compressed ioctl files in umockdev_testbed_load_ioctl().
  • Add example umockdev and ioctl files for a gphoto camera and an MTP capable mobile phone.
  • Fix building with automake 1.11.3 and Vala 0.16.
  • Generalize ioctl recording and emulation for ioctls with simple structs, i. e. no pointer fields. This makes it much easier to add more ioctls in the future.
  • Store return values of ioctls in records, as they are not always 0 (like EVIOCGBIT)
  • Add support for ioctl ranges (like EVIOCGABS) and ioctls with variable length (like EVIOCGBIT).
  • Add all reading evdev ioctls, for recording and mocking input devices like touch pads, touch screens, or keyboards. (issue #1)

…read more
Source: FULL ARTICLE at Planet Ubuntu

Remote command in variable using ssh

By seloum57

Hi, I’ve an issue in a shell script:

I’m opening an ssh connection to a remote server, then I want to store the result of a ls command in a variable, but it doesn’t work: the ls is done on the local machine.

ssh user@server << EOF
ls # works as expected (ls is done remotely)
test=`ls` # the ls is done locally and not remotely
EOF

Note: I have to use EOF, because they are several others commands done during the ssh.

any solution for this problem ?

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Error in Comparison value

By Rushab

Hi I have written below Script

IFS=:
while read emp_id_ name manager department;
do echo “$emp_id_”;
count=`sqlplus -s sys/orcl as sysdba << EOF
select count(*) from employee where emp_id = (‘$emp_id_’);
exit;
EOF`;
echo “$count” ;
if [ $count == 1 ] ; then echo “data exist” else echo “not exist” ; fi;
done < employee_data.txt

In employee_data file data as below:-
1:rushabh:4:IT

I employee table data is already there with emp_id = 1

now when I am comparing data its returning not exist
but it should return “data exist”

where is the problem in my script ?

please help me out from this problem?
thanks in advance

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Looping for comparison

By Akshay Hegde

Hi friends,,,

for comparison purpose i need to use nested loop….pls give one example..as I have confusion while file reading..my code looks somewhat like this..

Code:

Code:


awk 'FNR==NR{
{ getline < "file.dat" ; la=$1 }
{ getline < "file.dat" ; lo=$2 }
{ getline < "file.dat" ; p=$2+0.1 }
{ getline < "ifile.dat" ; m=$2-0.1 } So then here...I want read 1st and 2nd field of 2nd file...
like this...
{getline < "file2.dat"}; c=$1
{getline < "file2.dat"}; cd=$2
if(c >=m && cd <=a) then next if statement else read next 1st and 2nd field of file...once file2 comparison gets over (EOF)
print some result and read next fields of 1st file


if anyone can explain it will be helpful..


…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Log file Creation

By cnrj

Hi

I have unix script which does execute some OS commands and DB Commands. I would like to create log file for each command execution, Could some one advise how do we create log file.

Example Script:


###########################################################################
ORACLE_SID=ERS11G
ORACLE_HOME=/u03/app/oracle/product/11.2.0/db_1
LD_LIBRARY_PATH=$ORACLE_HOME/lib
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID ORACLE_HOME PATH LD_LIBRARY_PATH
###################################### Defining the Paths####################
SOURCETYPE=$1
INPUTFILESPATH=/ersdg3/ERS/TEST/RIO/files
BASEPATH=/ersdg3/ERS/TEST
ARCHIVEPATH=$BASEPATH/$SOURCETYPE/archive
CONTROLFILEPATH=$BASEPATH/$SOURCETYPE/control
AUDITFILENAME=${SOURCETYPE}_AUDIT_FILE.TXT
SOURCELOADER=${SOURCETYPE}_SOURCE_LOADER
AUDITCONTROLFILENAME=${SOURCETYPE}_REC_CNT.ctl
SOURCECONTROLFILENAME=$SOURCETYPE.ctl
SOURCECONTROLFILENAMENEW=${SOURCETYPE}_NEW.ctl
SOURCETABLENAME=ERS_${SOURCETYPE}_SRC
ARCHAUDITFILEPATH=${ARCHIVEPATH}/auditfiles
USERID=ETL_ERS
PASSWORD=ETL_ERS
SCHEMA=ERS11G
#####################################End of Paths###########################
cd $INPUTFILESPATH
################# Entry into Audit Table####################################
if [ -f *.LOG ]
then
sqlplus -s -L ETL_ERS/ETL_ERS@ERS11G<<EOF
set feedback off heading off
#exec ETL_LOG.P_LOG_START_PROCESS(trunc(sysdate),'${SOURCELOADER}','ETL_SRC');
exit;
EOF
else
echo "Files doesnt exist"
exit;
fi
####################End of Entry into Audit Table##########################
ls *.LOG >FILE.LIST
###################Check whether Audit file Exists#########################
if [ -f $AUDITFILENAME ]
then
rm $AUDITFILENAME
else
touch $AUDITFILENAME
fi
#########################################################################
while read filename
do
##############Date Format for Sql Loader Script and for Directory Creation#####
filename=$filename
fname=${filename%%.*}
date1=${fname##*_}
date=`print $date1 |cut -c1-8`
dat=`print $date |cut -c7-8`
yr=`print $date |cut -c1-4`
mon=`print $date |cut -c5-6`
var01="Jan"
var02="Feb"
var03="Mar"
var04="Apr"
var05="May"
var06="Jun"
var07="Jul"
var08="Aug"
var09="Sep"
var10="Oct"
var11="Nov"
var12="Dec"
val=$( eval eval echo $var$mon )
DATE="$dat-$val-$yr"
dir=${SOURCETYPE}_${DATE}
echo $dir
############End of Date Format################################################
done <FILE.LIST


…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

How to produce a executable Oracle script from bash script?

By jediwannabe

Hi here’s my code

Code:


${ORACLE_HOME}/bin/sqlplus /nolog <<!EOF
--step 5 create db script start
set feedback off
set heading off
set echo off
conn / as sysdba
spool ${ORACLE_SID}_db_link.sql

SELECT 'CREATE '||DECODE(U.NAME,'PUBLIC','public ')||'DATABASE LINK '||CHR(10)
||DECODE(U.NAME,'PUBLIC',Null, 'SYS','',U.NAME||'.')|| L.NAME||chr(10)
||'CONNECT TO ' || L.USERID || ' IDENTIFIED BY "'||L.PASSWORD||'" USING
'''||L.HOST||''''
||chr(10)||';' TEXT
FROM SYS.LINK$ L, SYS.USER$ U
WHERE L.OWNER# = U.USER#;

spool off

set feedback on
set heading on
set echo on

!EOF


here’s the output where i run the script

Code:

[oracle@TU-RH5 manual_upgrade]$ export ORACLE_SID=SUPERB
[oracle@TU-RH5 manual_upgrade]$ /home/oracle/chunhung/NI/manual_upgrade/create_db_link.sh

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Feb 5 17:59:16 2013

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

SQL> SQL> SQL> SQL> SQL> Connected.
SQL> SQL> SQL> 2 3 4 5 6 7
CREATE DATABASE LINK
SUPERB_ADMIN.UEM_CBS_DBLINK
CONNECT TO ABC_ADMIN IDENTIFIED BY "" USING
'/s01/oracle/product/10.2.0/db_1'
;

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


my output file SUPERB_db_link.sql

looks like the following

Code:

SQL>
SQL> SELECT 'CREATE '||DECODE(U.NAME,'PUBLIC','public ')||'DATABASE LINK '||CHR(10)
2 ||DECODE(U.NAME,'PUBLIC',Null, 'SYS','',U.NAME||'.')|| L.NAME||chr(10)
3 ||'CONNECT TO ' || L.USERID || ' IDENTIFIED BY "'||L.PASSWORD||'" USING
4 '''||L.HOST||''''
5 ||chr(10)||';' TEXT
6 FROM SYS.LINK$ L, SYS.USER$ U
7 WHERE L.OWNER# = U.USER#;

CREATE DATABASE LINK
SUPERB_ADMIN.UEM_CBS_DBLINK
CONNECT TO ABC_ADMIN IDENTIFIED BY "" USING
'/s01/oracle/product/10.2.0/db_1'
;

SQL>
SQL> spool off


unfortunately this is not what I want.

what I want is

Code:

CREATE DATABASE LINK
SUPERB_ADMIN.UEM_CBS_DBLINK
CONNECT TO ABC_ADMIN IDENTIFIED BY "" USING
'/s01/oracle/product/10.2.0/db_1'
;


would really appreciate if someone could help me on this!

thanks a lot!

Source: FULL ARTICLE at The UNIX and Linux Forums

Pexpect telnet into one device and then from there to another

By kaf3773

I am trying to use pexpect to telnet to a device and then subsequently
telnet from that device to another device but i am unable to. Here is the
script i wrote and the error i am getting

I will appreciate help very much. Thanks

Code:

import pexpect

child = pexpect.spawn('telnet 192.168.2.45');

child.expect('assword:');
child.sendline('getin');

child.expect('AS-C5350-02>');
child.sendline('telnet 192.168.1.2');
child.expect('nTrying 192.168.1.2 ... OpennnnUser Access VerificationnnPassword:');
child.sendline('cisco');
child.expect('ipipgw01>');
child.sendline('sh clock');
child.sendline('exit');

child.expect(pexpect.EOF);

print child.before;


This is the error i keep getting

Code:

Traceback (most recent call last):
File "expect_telnetback.py", line 14, in
child.expect('nTrying 192.168.1.2 ... OpennnnUser Access VerificationnnPassword:');
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1311, in expect
return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1325, in expect_list
return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1409, in expect_loop
raise TIMEOUT (str(e) + 'n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().

version: 2.3 ($Revision: 399 $)
command: /usr/bin/telnet
args: ['/usr/bin/telnet', '192.168.2.45']
searcher: searcher_re:
0: re.compile("
Trying 196.192.7.14 ... Open

User Access Verification

Password:")
buffer (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open

User Access Verification

Password:
before (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open

User Access Verification

Password:
after:
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 26275
child_fd: 3
closed: False
timeout: 30
delimiter:
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1


Source: FULL ARTICLE at The UNIX and Linux Forums

Unexpected EOF while looking for matching `'' when ran from a cron job

By tiagom

Since cPanel does not support deleting emails older then X amount of days I am using the following on a Cron Job.

Code:

find -P /home/user/mail/domain/ -mindepth 2 -mtime '+366' -type f -printf '"%p"n' | grep -v '/Important' | grep -v '/.Important' | xargs -I {} rm -r "{}"


Executing it via SSH shows that it completes without issue but when it runs from a Cron Job i get:

Quote:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `”
/bin/sh: -c: line 1: syntax error: unexpected end of file


Any help is much appreciated. Thanks

Source: FULL ARTICLE at The UNIX and Linux Forums

Looping/Reading file contents not working

By DBnixUser

Hi,

I am doing something basic, but I am missing something. Im trying to read the contents of a file and taking those values and connecting to a database. However, it only connect to one (or reads in) value and then exists.

Here is what it looks like:

listname.txt

Code:

db1
db2
db3


Script:

Code:

dbcontent=/usr/home/listname.txt
echo "Enter userid"
read USERID
echo "Enter passwd:"
stty -echo
read -s PASSWD
stty echo

while read dbname;
do
#Connect to SQLPlus
sqlplus -S test/test123@$dbname
select ora_database_name from dual;
prompt my name is $USERID and my password is $PASSWD;
exit;
EOF
done < $dbcontent


It doesn’t read all the lines (loop through) just exits after one run.
I am also trying to have it connect to each database (in the list).

Source: FULL ARTICLE at The UNIX and Linux Forums

Help with calling to file for a username and password combo

By cashman04

Hokay…first post, and I have been doing Linux scripting for a total of 2 days now. I think I am doing pretty well, but awk and arrays(what I think I need here) is a bit above me so far.

I have written a script that will take and either create or modify 5 users, and passwords.

It checks the device to see if a user exists, if they don’t, it adds the user, and gives them sudo access, and changes the password to the one specified. If they do exist, it changes the password to the specified password, and then checks for sudoers access, and gives the user access if they don’t have it.

Currently this script isn’t really scaleable. it us for 5 users. It can be tweaked to add more, but I know there is a better way to do it, I just don’t know how at my level of knowledge.

What I want to have it do, is call to a text file that has something like
username password
username password
username password

And have set the username and password on each line, on loop, till EOF. I don’t know how to do that, and have it keep username on line1 with username on line1, and username on line2 with username on line2 successfully.

I have already seen a few ways I can clean up the existing code and make it cleaner, but I am trying to get this part figured out before tomorrow night first.

If you have any help, please let me know.

Here is my current script: (it is much cleaner than how it pasted in here)


#!/bin/sh
user1=blah
user2=blahette
user3=blahjr
user4=mrblah
user5=blaaaaaaaa
password1=adsfasdfaf
password2=asdfasdfasd
password3=asdfasdfasd
password4=asdfadsf
password5=asdfasd
createuser1(){
useradd -m $user1
sh -c "echo '$user1 ALL=(ALL) ALL' >> /etc/sudoers"
echo -e "$password1n$password1" | (passwd --stdin $user1)
}
changepass1(){
addroot(){
sh -c "echo '$user1 ALL=(ALL) ALL' >> /etc/sudoers"
echo $user1 "has been given root access"
}
printroot(){
echo $user1 already has root access
}
echo -e "$password1n$password1" | (passwd --stdin $user1)
if [ `grep $user1 /etc/sudoers | wc -l` -lt "1" ];
then addroot
else printroot

fi
}

createuser2(){
useradd -m $user2
sh -c "echo '$user2 ALL=(ALL) ALL' >> /etc/sudoers"
echo -e "$password2n$password2" | (passwd --stdin $user2)
}

changepass2(){
addroot(){
sh -c "echo '$user2 ALL=(ALL) ALL' >> /etc/sudoers"
echo $user2 "has been given root access"
}
printroot(){
echo $user2 already has root access
}
echo -e "$password2n$password2" | (passwd --stdin $user2)
if [ `grep $user2 /etc/sudoers | wc -l` -lt "1" ];
then addroot
else printroot

fi
}

createuser3(){
useradd -m $user3
sh -c "echo '$user3 ALL=(ALL) ALL' >> /etc/sudoers"
echo -e "$password3n$password3" | (passwd --stdin $user3)
}
changepass3(){
addroot(){
sh -c "echo '$user3 ALL=(ALL) ALL' >> /etc/sudoers"
echo $user3 "has been given root access"
}
printroot(){
echo $user3 already has root access
}
echo -e "$password3n$password3" | (passwd --stdin $user3)
if [ `grep $user3 /etc/sudoers | wc -l` -lt "1" ];
then addroot
else printroot

fi
}

createuser4(){
useradd -m $user4
sh -c "echo '$user4 ALL=(ALL) ALL' >> /etc/sudoers"
echo -e "$password4n$password4" | (passwd --stdin $user4)
}
changepass4(){
addroot(){
sh -c "echo '$user4 ALL=(ALL) ALL' >> /etc/sudoers"
echo $user4 "has been given root access"
}
printroot(){
echo $user4 already has root access
}
echo -e "$password4n$password4" | (passwd --stdin $user4)
if [ `grep $user4 /etc/sudoers | wc -l` -lt "1" ];
then addroot
else printroot

fi
}

createuser5(){
useradd -m $user5
sh -c "echo '$user5 ALL=(ALL) ALL' >> /etc/sudoers"
echo -e "$password5n$password5" | (passwd --stdin $user5)
}
changepass5(){
addroot(){
sh -c "echo '$user5 ALL=(ALL) ALL' >> /etc/sudoers"
echo $user5 "has been given root access"
}
printroot(){
echo $user5 already has root access
}
echo -e "$password5n$password5" | (passwd --stdin $user5)
if [ `grep $user5 /etc/sudoers | wc -l` -lt "1" ];
then addroot
else printroot

fi
}

if [ `grep $user1 /etc/passwd | wc -l` -gt "0" ];
then changepass1 && echo $user1 "already exists , password has been changed."
else createuser1 && echo $user1 "has been created and given root access."
fi
if [ `grep $user2 /etc/passwd | wc -l` -gt "0" ];
then changepass2 && echo $user2 "already exists , password has been changed."
else createuser2 && echo $user2 "has been created and given root access."
fi
if [ `grep $user3 /etc/passwd | wc -l` -gt "0" ];
then changepass3 && echo $user3 "already exists , password has been changed."
else createuser3 && echo $user3 "has been created and given root access."
fi
if [ `grep $user4 /etc/passwd | wc -l` -gt "0" ];
then changepass4 && echo $user4 "already exists , password has been changed."
else createuser4 && echo $user4 "has been created and given root access."
fi
if [ `grep $user5 /etc/passwd | wc -l` -gt "0" ];
then changepass5 && echo $user5 "already exists , password has been changed."
else createuser5 && echo $user5 "has been created and given root access."
fi
exit


Source: FULL ARTICLE at The UNIX and Linux Forums