cancel
Showing results for 
Search instead for 
Did you mean: 

Script input

 
SOLVED
Go to solution
Charles Keyser
Frequent Advisor

Script input

I have a script that was written in a previous thread. We are using the Help Desk to reset and enable accounts can some help me update this I seem to have a brain cramp. Here is the script. Any help would be greatly appreciated.

#!/usr/bin/sh
#
#
#
trap '' INT
function cont
{
print -n "Do You Wish to Continue Y/N : "
read answ
if [[ $answ = [Yy] ]]
then
return 0
else
return 1
fi
}
while true
do
clear
print -n "
* HELP DESK MENU *
$(uname -n)
HELLO: $(whoami)
===================================================
1. Run Restricted SAM to reset passwords.

2. Display printer status / print jobs.
a. Enter lpstat -p to view all printers
b. Enter lpstat -o to view all print request

3. Cancel a print job.

4. Cancel ALL print jobs for a printer.

5. EXIT this program and RETURN TO COMMAND LINE.

6. Reset users passwords

7. Enable users account

===================================================

Select an Option # from above: "

read answer
case "$answer" in
5*|Qq|bye|Ee ) print "Quitting! See You Later, $(whoami)" ; exit ;;
1) if cont
then
. /usr/sbin/sam
fi;;
2) if (( $? == 0 ))
then
print -n "Enter Printer Name: "
read prtr
lpstat $prtr
print -n "OK to clear screen [Hit Any Key]"
read h
fi;;
3) if (( $? == 0 ))
then
print -n "Enter Printer Name-job#: "
read prtr
cancel $prtr
fi;;
4) if (( $? == 0 ))
then
print -n "..Enter printer name :"
read prtr_name
print -n "You enter printer ${prtr_name}"
print -n " Is this correct Y/N "
read answ
if [[ "$answ" = [Yy] ]]
then
lpstat $prtr_name | grep $prtr_name | sort -k1 | cut -d " " -f1 > $prtr_name.out
for rem_prt in `cat $prtr_name.out`
do
cancel $rem_prt
done
else
echo "No Such Printer"
fi



fi;;
esac
done




27 REPLIES 27
James R. Ferguson
Acclaimed Contributor
Solution

Re: Script input

Hi Charles:

So your question is?

A search might point you to this thread:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1218120768120+28353475&threadId=1029835

Regards!

...JRF...
Charles Keyser
Frequent Advisor

Re: Script input

Sorry I really have a brain cramp. What I would like to do is have 6 an 7 executed by the help desk.
When the select 6 I would like for a question to come up and ask "enter user ID"
once that happens it should generate an for a system generated password. Once completed the help desk will have the number, call the user and provide them the information. The user then should be able to log on enter this and change their password. The other number 7 is pretty much the same enables and resets their password

I hope this helps.
Chris Vail
Honored Contributor

Re: Script input

Usually I structure these things differently. I start by putting them in a 'while true' loop. This means that no matter what the user does, the menu script always loops. But include an exit option
while true
do
......your script

x|X) exit;;
done

Also, on every case....esac menu, I usually add an * to the end. So that if the user pressess anything except a valid key, s/he will get an error message.
while true
do
case $CHOICE in
1) (do something);;
2) (do something);;
x|X) exit;;
*) echo "Invalid selection! Press [ENTER] to continue! \c"; echo "\007";read NOTHING;;
esac
done


Chris
Charles Keyser
Frequent Advisor

Re: Script input

Chris

I guess I am a little confused. Maybe a lot today then others.

while true
do

Is added at the beginning of my script?

SO if I add a line for number 6

6) if cont
then print -n "Enter users ID"

THIS is where I get hung up I have tried
usr/lbin/modprpw -x $myUserAcctName
/usr/lbin/modprpw -l -k -m
rstrpw=YES,exptm=45,nullpw=NO $myUserAcctName

It just does not seem to work. Am I adding this incorrectly? I wil be running this script on 3 servers 2 are 10.20's the other is 11.00
It has been awhile since I have written scripts. A long while. Any advice or input is greatly appreciated.

Thank you again for your time and patience

-Charlie
James R. Ferguson
Acclaimed Contributor

Re: Script input

Hi (again):

> once that happens it should generate an for a system generated password. Once completed the help desk will have the number, call the user and provide them the information. The user then should be able to log on enter this and change their password. The other number 7 is pretty much the same enables and resets their password

OK, if you want a random, clear-text password, use the Perl script I wrote here:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1231878

If you want an encrypted, random password use my variation here:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1252591

I also agree with Chris: for menu-based scripts, a 'while true do;' loop with an 'continue', 'break' and 'exit' controls works very well.

Regards!

...JRF...
Chris Vail
Honored Contributor

Re: Script input

>Chris
>I guess I am a little confused. Maybe a lot today then others.

I spend a lot of my life confused. You're not alone!

>while true
>do

>Is added at the beginning of my script?

Yes. The final 'done' is at the end of the script.

>SO if I add a line for number 6
>6) if cont
>then print -n "Enter users ID"

>THIS is where I get hung up I have tried
>usr/lbin/modprpw -x $myUserAcctName
>/usr/lbin/modprpw -l -k -m
>strpw=YES,exptm=45,nullpw=NO >$myUserAcctName

>It just does not seem to work. Am I adding this incorrectly? I wil be running this script on 3 servers 2 are 10.20's the other is 11.00
>It has been awhile since I have written scripts. A long while. Any advice or input is greatly appreciated.

Inside your case...esac statement you have already done most of your if/then logic. I would structure item 6 like this:
6) echo "Username to modify \c"; read USER
TESTNAME=`grep $USER /etc/passwd|awk -F: '{ print $1 }'`
if test "$USER" != "$TESTUSER"
then
echo "$USER is invalid!"
else
passwd $USER
fi;;

This snippet takes input from the operator, and compares it against the password database. It runs the password command if it matches, and echos an error code if it doesn't.

Because it is in a 'while true ' loop, the menu will display again and it can be chosen again.

>Thank you again for your time and patience

The best way to say 'thanks' is to assign points!


Chris
Charles Keyser
Frequent Advisor

Re: Script input

Thanks again. I have added your logic to the script when I select the menu number

6. Reset User Passwords

I receive a prompt

Username to modify

I eneter a user ada0160 who's account is locked

and I even enter mine cjk1402 to change my password it loops back to the main screen not allow any changes. I do see invalid user flash really quick

Again Thank you for your input.



Chris Vail
Honored Contributor

Re: Script input

Yes, I did leave something out of that previous snippet. Here I will correct it:

6) echo "Username to modify \c"; read USER
TESTNAME=`grep $USER /etc/passwd|awk -F: '{ print $1 }'`
if test "$USER" != "$TESTUSER"
then
echo "$USER is invalid!"
echo "Press [ENTER] to continue. \c"
read NOTHING
else
passwd $USER
fi;;
Charles Keyser
Frequent Advisor

Re: Script input

Chris

I finally realized that I did not select the drop menu for the points. I have set your reply s to 10. You have been very helpful.

-Charlie