- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script problem
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
02-05-2006 11:54 AM
02-05-2006 11:54 AM
Script problem
I am planning to use the following script for changing user password. The script working fine when i supply non existant user. It also works fine when i put an existing user but throws a error in the screen
./menu.sh[27]: Ayub: A test command parameter is not valid.
#!/bin/sh
clear # Clear the screen.
echo " ------- ----"
echo "Choose one of the following option:"
echo
echo "[P] for Password Change"
echo "[E] for Exit"
echo
read OPTION
case "$OPTION" in
"E" | "e" )
# Accept upper or lowercase input.
echo
echo "You chose to exit"
;;
# Note double semicolon to terminate each option.
"P" | "p" )
echo
echo "You choose password change"
echo "Enter the user name"
read USER
X=`finger $USER |grep "In real life" |cut -d ":" -f3`
finger $USER | grep "In real life" |tr -s " " |cut -d ":" -f2,3| cut -d " " -f2,6,7,8|grep -n " ">>list.txt
echo "Select userlogin from the following list"
cat list.txt
rm list.txt
if test $X = "???"
then
echo "No such user please try again"
else
echo "Enter the login name"
read LNAME
if test $LNAME = "jgan"
then
echo "You cannot change root password"
else
echo "password of "$LNAME" is changed"
fi
fi
;;
esac
How can i ommit that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2006 12:15 PM
02-05-2006 12:15 PM
Re: Script problem
if test $X = "???"
should be
if test "${X}" = "???" #note the quotes
The more generally used form is
if [ "${X}" = "???" ] #note the space after '[' and before ']' -- very important
You should quote every variable that is tested that might be a null string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2006 12:33 PM
02-05-2006 12:33 PM
Re: Script problem
That problem is solved but it is now not working for a invalid user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2006 01:57 PM
02-05-2006 01:57 PM
Re: Script problem
X=`finger $USER |grep "In real life" |cut -d ":" -f3`
finger $USER | grep "In real life" |tr -s " " |cut -d ":" -f2,3| cut -d " " -f2,6,7,8|grep -n " ">>list.txt
echo "Select userlogin from the following list"
cat list.txt
rm list.txt
as,
id ${USER}
if [[ $? -ne 0 ]]
then
echo "No such user please try again"
else
echo "Enter the login name"
read LNAME
if [[ "${LNAME}" = "jgan" ]]
then
echo "You cannot change root password"
else
echo "password of "$LNAME" is changed"
fi
fi
It will work.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2006 02:04 PM
02-05-2006 02:04 PM