- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:14 AM
10-20-2005 01:14 AM
It allowes sudoers to add users to a system. however, it checks that they put the correct information in. ie. username must be six characters, branch must be 4. and no Null values for the user's real name. These things are constrained by the application the user account are for (a progress database).
While this works okay, the script exits at the first failure. e.g if they put a 5 letter log on name and a 3 letter branch name, they are only told about the incorrect log on name. Can anyone suggest a way to enable it to echo all the errors:
The output i want is a list of what they did wrong and then the part about 'account created aborted'
#! /bin/ksh
clear
echo "Enter the login name of the User you want to add: \c"
read USER
echo "Enter the user's FIRST name: \c"
read FIRST
echo "Enter the user's SURNAME: \c"
read SURNAME
echo "Which Branch is the user based at? (four letters): \c"
read BRANCH
BRANCH=`echo $BRANCH | tr '[a-z]' '[A-Z]'`
FOUR=5
SIX=7
USERSIX=`echo $USER|wc -m`
BRANCHFOUR=`echo $BRANCH|wc -m`
if test $USERSIX != $SIX
then
echo "The user name must be 6 characters long"
elif test $BRANCHFOUR != $FOUR
then
echo "The Branch name is not 4 characters long"
elif [ $2 -z "$FIRST" -o -z "$SURNAME" ]
then
echo "You have entered a NULL for the users name"
elif [ $4 "$USERSIX" != "$SIX" -o "$BRANCHFOUR" != "$FOUR" -o -z "$FIRST" -o -z "$SURNAME" ]
then
echo "Account Creation ABORTED"
else
clear
echo "The following account is about to be created:"
echo "Username: $USER"
echo "Name: $FIRST $SURNAME"
echo "Branch: $BRANCH"
echo "\nIs this Correct? Please choose y or n"
read Answer
while [ $Answer != 'n' ] && [ $Answer != 'y' ]
do
echo "Please press y or n and press enter"
read Answer
done
if [ $Answer = 'n' ]
then
echo "User NOT added"
else
/usr/sbin/useradd -d /home/$USER -m -c "$FIRST $SURNAME - ($BRANCH)" -s /usr/bin
/ksh -g coins -k /etc/skel/coins $USER
passwd $USER
passwd -f $USER
fi
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:18 AM
10-20-2005 01:18 AM
Re: shell script
If you want everything checked you could just do multiple if/then/fi statements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:20 AM
10-20-2005 01:20 AM
Re: shell script
There's no simple way to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:42 AM
10-20-2005 01:42 AM
Re: shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:42 AM
10-20-2005 01:42 AM
Re: shell script
if [ $1 = "test1" ] && [ $2 = "test2" ]
then
echo "do echo all ok"
else
if
elif
else
fi
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:49 AM
10-20-2005 01:49 AM
Re: shell script
is there no other way? like if a then b, but carry on with the rest of the script :-(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:54 AM
10-20-2005 01:54 AM
Re: shell script
Your checks would then write error messages to the error log instead of the screen (make sure you use append - >> - so as not to overwrite earlier errors). At the end, you would then have a test:
if -f error.log
then
your procedure for a failed process.
if -f means if error.log exists and is a standard file - this test will fail if error.log is empty.
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 01:55 AM
10-20-2005 01:55 AM
Re: shell script
if [ $1 = "test1" ] && [ $2 = "test2" ]
then
arch=OK
else
echo "error in read 1=$1, 2=$2"
exit
fi
if [ $arch = "OK" ]
then
...
elif
else
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 02:25 AM
10-20-2005 02:25 AM
Re: shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 02:28 AM
10-20-2005 02:28 AM
Solution#! /bin/ksh
clear
echo "Enter the login name of the User you want to add: \c"
read USER
echo "Enter the user's FIRST name: \c"
read FIRST
echo "Enter the user's SURNAME: \c"
read SURNAME
echo "Which Branch is the user based at? (four letters): \c"
read BRANCH
BRANCH=`echo $BRANCH | tr '[a-z]' '[A-Z]'`
FOUR=5
SIX=7
USERSIX=`echo $USER|wc -m`
BRANCHFOUR=`echo $BRANCH|wc -m`
VALIDUSER=true
if test $USERSIX != $SIX
then
echo "The user name must be 6 characters long"
VALIDUSER=false
fi
if test $BRANCHFOUR != $FOUR
then
echo "The Branch name is not 4 characters long"
VALIDUSER=false
fi
if [ $2 -z "$FIRST" -o -z "$SURNAME" ]
then
echo "You have entered a NULL for the users name"
VALIDUSER=false
fi
if [ $4 "$USERSIX" != "$SIX" -o "$BRANCHFOUR" != "$FOUR" -o -z "$FIRST" -o -z "$SURNAME" ]
then
echo "Account Creation ABORTED"
VALIDUSER=false
fi
if [$VALIDUSER]
then
clear
echo "The following account is about to be created:"
echo "Username: $USER"
echo "Name: $FIRST $SURNAME"
echo "Branch: $BRANCH"
echo "\nIs this Correct? Please choose y or n"
read Answer
while [ $Answer != 'n' ] && [ $Answer != 'y' ]
do
echo "Please press y or n and press enter"
read Answer
done
if [ $Answer = 'n' ]
then
echo "User NOT added"
else
/usr/sbin/useradd -d /home/$USER -m -c "$FIRST $SURNAME - ($BRANCH)" -s /usr/bin
/ksh -g coins -k /etc/skel/coins $USER
passwd $USER
passwd -f $USER
fi
fi
PS: just keeping a variable to indicate a valid user and negating it if any input is invalid...
hth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 02:32 AM
10-20-2005 02:32 AM
Re: shell script
if $VALIDUSER
sorry for the typo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 03:16 AM
10-20-2005 03:16 AM
Re: shell script
i presume if validates true or false automatically like that.
The other bit is great also.
:-)
exactly what i wanted.
11/10!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 03:20 AM
10-20-2005 03:20 AM
Re: shell script
have i written this in a stupid way? i am relative beginer.
It may seem over the top, but this will be run by people of with very limited techincal (read intellecutal) abilities, on a service desk using sudo trough a client calling the shell script for a programme called 'coins'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2006 09:59 PM
02-06-2006 09:59 PM