<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935219#M740322</link>
    <description>Hello, I've written a script as outlined below.&lt;BR /&gt;&lt;BR /&gt;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).&lt;BR /&gt;&lt;BR /&gt;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:&lt;BR /&gt;&lt;BR /&gt;The output i want is a list of what they did wrong and then the part about 'account created aborted'&lt;BR /&gt;&lt;BR /&gt;#! /bin/ksh&lt;BR /&gt;clear&lt;BR /&gt;&lt;BR /&gt;echo "Enter the login name of the User you want to add: \c"&lt;BR /&gt;read USER&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user's FIRST name: \c"&lt;BR /&gt;read FIRST&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user's SURNAME: \c" &lt;BR /&gt;read SURNAME&lt;BR /&gt;&lt;BR /&gt;echo "Which Branch is the user based at? (four letters): \c"&lt;BR /&gt;read BRANCH&lt;BR /&gt;BRANCH=`echo $BRANCH | tr '[a-z]' '[A-Z]'`&lt;BR /&gt;&lt;BR /&gt;FOUR=5&lt;BR /&gt;SIX=7&lt;BR /&gt;USERSIX=`echo $USER|wc -m`&lt;BR /&gt;BRANCHFOUR=`echo $BRANCH|wc -m`&lt;BR /&gt;&lt;BR /&gt;if test $USERSIX != $SIX&lt;BR /&gt;then&lt;BR /&gt;echo "The user name must be 6 characters long" &lt;BR /&gt;&lt;BR /&gt;elif test $BRANCHFOUR != $FOUR&lt;BR /&gt;then&lt;BR /&gt;echo "The Branch name is not 4 characters long"&lt;BR /&gt;&lt;BR /&gt;elif [ $2 -z "$FIRST" -o -z "$SURNAME" ]&lt;BR /&gt;then&lt;BR /&gt;echo "You have entered a NULL for the users name"&lt;BR /&gt;&lt;BR /&gt;elif [ $4 "$USERSIX" != "$SIX" -o "$BRANCHFOUR" != "$FOUR" -o -z "$FIRST" -o -z "$SURNAME" ]&lt;BR /&gt;then&lt;BR /&gt;echo "Account Creation ABORTED"&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;clear&lt;BR /&gt;echo "The following account is about to be created:"&lt;BR /&gt;echo "Username: $USER"&lt;BR /&gt;echo "Name: $FIRST $SURNAME"&lt;BR /&gt;echo "Branch: $BRANCH"&lt;BR /&gt;echo "\nIs this Correct? Please choose y or n"&lt;BR /&gt;&lt;BR /&gt;read Answer&lt;BR /&gt;while [ $Answer != 'n'  ] &amp;amp;&amp;amp; [ $Answer != 'y' ]&lt;BR /&gt;do&lt;BR /&gt;echo "Please press y or n and press enter"&lt;BR /&gt;read Answer&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;if [ $Answer = 'n' ]&lt;BR /&gt;then&lt;BR /&gt;echo "User NOT added"&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;/usr/sbin/useradd -d /home/$USER -m -c "$FIRST $SURNAME - ($BRANCH)" -s /usr/bin&lt;BR /&gt;/ksh -g coins -k /etc/skel/coins $USER&lt;BR /&gt;&lt;BR /&gt;passwd $USER&lt;BR /&gt;passwd -f $USER&lt;BR /&gt;fi&lt;BR /&gt;fi</description>
    <pubDate>Thu, 20 Oct 2005 08:14:23 GMT</pubDate>
    <dc:creator>Tom Satinet</dc:creator>
    <dc:date>2005-10-20T08:14:23Z</dc:date>
    <item>
      <title>shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935219#M740322</link>
      <description>Hello, I've written a script as outlined below.&lt;BR /&gt;&lt;BR /&gt;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).&lt;BR /&gt;&lt;BR /&gt;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:&lt;BR /&gt;&lt;BR /&gt;The output i want is a list of what they did wrong and then the part about 'account created aborted'&lt;BR /&gt;&lt;BR /&gt;#! /bin/ksh&lt;BR /&gt;clear&lt;BR /&gt;&lt;BR /&gt;echo "Enter the login name of the User you want to add: \c"&lt;BR /&gt;read USER&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user's FIRST name: \c"&lt;BR /&gt;read FIRST&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user's SURNAME: \c" &lt;BR /&gt;read SURNAME&lt;BR /&gt;&lt;BR /&gt;echo "Which Branch is the user based at? (four letters): \c"&lt;BR /&gt;read BRANCH&lt;BR /&gt;BRANCH=`echo $BRANCH | tr '[a-z]' '[A-Z]'`&lt;BR /&gt;&lt;BR /&gt;FOUR=5&lt;BR /&gt;SIX=7&lt;BR /&gt;USERSIX=`echo $USER|wc -m`&lt;BR /&gt;BRANCHFOUR=`echo $BRANCH|wc -m`&lt;BR /&gt;&lt;BR /&gt;if test $USERSIX != $SIX&lt;BR /&gt;then&lt;BR /&gt;echo "The user name must be 6 characters long" &lt;BR /&gt;&lt;BR /&gt;elif test $BRANCHFOUR != $FOUR&lt;BR /&gt;then&lt;BR /&gt;echo "The Branch name is not 4 characters long"&lt;BR /&gt;&lt;BR /&gt;elif [ $2 -z "$FIRST" -o -z "$SURNAME" ]&lt;BR /&gt;then&lt;BR /&gt;echo "You have entered a NULL for the users name"&lt;BR /&gt;&lt;BR /&gt;elif [ $4 "$USERSIX" != "$SIX" -o "$BRANCHFOUR" != "$FOUR" -o -z "$FIRST" -o -z "$SURNAME" ]&lt;BR /&gt;then&lt;BR /&gt;echo "Account Creation ABORTED"&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;clear&lt;BR /&gt;echo "The following account is about to be created:"&lt;BR /&gt;echo "Username: $USER"&lt;BR /&gt;echo "Name: $FIRST $SURNAME"&lt;BR /&gt;echo "Branch: $BRANCH"&lt;BR /&gt;echo "\nIs this Correct? Please choose y or n"&lt;BR /&gt;&lt;BR /&gt;read Answer&lt;BR /&gt;while [ $Answer != 'n'  ] &amp;amp;&amp;amp; [ $Answer != 'y' ]&lt;BR /&gt;do&lt;BR /&gt;echo "Please press y or n and press enter"&lt;BR /&gt;read Answer&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;if [ $Answer = 'n' ]&lt;BR /&gt;then&lt;BR /&gt;echo "User NOT added"&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;/usr/sbin/useradd -d /home/$USER -m -c "$FIRST $SURNAME - ($BRANCH)" -s /usr/bin&lt;BR /&gt;/ksh -g coins -k /etc/skel/coins $USER&lt;BR /&gt;&lt;BR /&gt;passwd $USER&lt;BR /&gt;passwd -f $USER&lt;BR /&gt;fi&lt;BR /&gt;fi</description>
      <pubDate>Thu, 20 Oct 2005 08:14:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935219#M740322</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2005-10-20T08:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935220#M740323</link>
      <description>It is doing this becuase you are using if/then/elif.  If the first condition is true, nothing else will be checked.  That's the way the elif works.&lt;BR /&gt;&lt;BR /&gt;If you want everything checked you could just do multiple if/then/fi statements.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Oct 2005 08:18:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935220#M740323</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2005-10-20T08:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935221#M740324</link>
      <description>yes, i guess so.  It would be loads of code though.&lt;BR /&gt;&lt;BR /&gt;There's no simple way to do this?</description>
      <pubDate>Thu, 20 Oct 2005 08:20:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935221#M740324</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2005-10-20T08:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935222#M740325</link>
      <description>i was really looking for advice on how to do this. i know how elif works..... :-(</description>
      <pubDate>Thu, 20 Oct 2005 08:42:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935222#M740325</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2005-10-20T08:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935223#M740326</link>
      <description>You should  do a &amp;amp;&amp;amp; (and) test something like this:&lt;BR /&gt;&lt;BR /&gt;if [ $1 = "test1" ] &amp;amp;&amp;amp; [ $2 = "test2" ]&lt;BR /&gt;then&lt;BR /&gt; echo "do echo all ok"&lt;BR /&gt;else&lt;BR /&gt; if&lt;BR /&gt; elif&lt;BR /&gt; else&lt;BR /&gt; fi&lt;BR /&gt;fi</description>
      <pubDate>Thu, 20 Oct 2005 08:42:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935223#M740326</guid>
      <dc:creator>Jannik</dc:creator>
      <dc:date>2005-10-20T08:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935224#M740327</link>
      <description>yeah, it's very frustating. having to nest loads of ifs within each other, just to do something so simple.  &lt;BR /&gt;&lt;BR /&gt;is there no other way? like if a then b, but carry on with the rest of the script :-(</description>
      <pubDate>Thu, 20 Oct 2005 08:49:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935224#M740327</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2005-10-20T08:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935225#M740328</link>
      <description>You could set up an error log file at the beginning of the script. Null the error log before the checking starts (&amp;gt; error.log) to avoid errors from previous sessions showing up.&lt;BR /&gt;&lt;BR /&gt;Your checks would then write error messages to the error log instead of the screen (make sure you use append - &amp;gt;&amp;gt; - so as not to overwrite earlier errors). At the end, you would then have a test:&lt;BR /&gt;&lt;BR /&gt;if -f error.log&lt;BR /&gt;then&lt;BR /&gt;your procedure for a failed process.&lt;BR /&gt;&lt;BR /&gt;if -f means if error.log exists and is a standard file - this test will fail if error.log is empty.&lt;BR /&gt;&lt;BR /&gt;Mark Syder (like the drink but spelt different)</description>
      <pubDate>Thu, 20 Oct 2005 08:54:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935225#M740328</guid>
      <dc:creator>MarkSyder</dc:creator>
      <dc:date>2005-10-20T08:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935226#M740329</link>
      <description>you could do:&lt;BR /&gt;&lt;BR /&gt;if [ $1 = "test1" ] &amp;amp;&amp;amp; [ $2 = "test2" ]&lt;BR /&gt;then&lt;BR /&gt; arch=OK&lt;BR /&gt;else&lt;BR /&gt; echo "error in read 1=$1, 2=$2"&lt;BR /&gt; exit&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ $arch = "OK" ]&lt;BR /&gt;then&lt;BR /&gt;...&lt;BR /&gt;elif&lt;BR /&gt;else&lt;BR /&gt;fi</description>
      <pubDate>Thu, 20 Oct 2005 08:55:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935226#M740329</guid>
      <dc:creator>Jannik</dc:creator>
      <dc:date>2005-10-20T08:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935227#M740330</link>
      <description>I think that when you do the check, you shold not use elif, just if, because elif wont be tested when there is a match.</description>
      <pubDate>Thu, 20 Oct 2005 09:25:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935227#M740330</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2005-10-20T09:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935228#M740331</link>
      <description>try this&lt;BR /&gt;&lt;BR /&gt;#! /bin/ksh&lt;BR /&gt;clear&lt;BR /&gt;&lt;BR /&gt;echo "Enter the login name of the User you want to add: \c"&lt;BR /&gt;read USER&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user's FIRST name: \c"&lt;BR /&gt;read FIRST&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user's SURNAME: \c"&lt;BR /&gt;read SURNAME&lt;BR /&gt;&lt;BR /&gt;echo "Which Branch is the user based at? (four letters): \c"&lt;BR /&gt;read BRANCH&lt;BR /&gt;BRANCH=`echo $BRANCH | tr '[a-z]' '[A-Z]'`&lt;BR /&gt;&lt;BR /&gt;FOUR=5&lt;BR /&gt;SIX=7&lt;BR /&gt;USERSIX=`echo $USER|wc -m`&lt;BR /&gt;BRANCHFOUR=`echo $BRANCH|wc -m`&lt;BR /&gt;&lt;BR /&gt;VALIDUSER=true&lt;BR /&gt;&lt;BR /&gt;if test $USERSIX != $SIX&lt;BR /&gt;then&lt;BR /&gt; echo "The user name must be 6 characters long"&lt;BR /&gt; VALIDUSER=false&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if test $BRANCHFOUR != $FOUR&lt;BR /&gt;then&lt;BR /&gt; echo "The Branch name is not 4 characters long"&lt;BR /&gt; VALIDUSER=false&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ $2 -z "$FIRST" -o -z "$SURNAME" ]&lt;BR /&gt;then&lt;BR /&gt; echo "You have entered a NULL for the users name"&lt;BR /&gt; VALIDUSER=false&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ $4 "$USERSIX" != "$SIX" -o "$BRANCHFOUR" != "$FOUR" -o -z "$FIRST" -o -z "$SURNAME" ]&lt;BR /&gt;then&lt;BR /&gt; echo "Account Creation ABORTED"&lt;BR /&gt; VALIDUSER=false&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [$VALIDUSER]&lt;BR /&gt;then&lt;BR /&gt; clear&lt;BR /&gt; echo "The following account is about to be created:"&lt;BR /&gt; echo "Username: $USER"&lt;BR /&gt; echo "Name: $FIRST $SURNAME"&lt;BR /&gt; echo "Branch: $BRANCH"&lt;BR /&gt; echo "\nIs this Correct? Please choose y or n"&lt;BR /&gt;&lt;BR /&gt; read Answer&lt;BR /&gt; while [ $Answer != 'n' ] &amp;amp;&amp;amp; [ $Answer != 'y' ]&lt;BR /&gt; do&lt;BR /&gt;  echo "Please press y or n and press enter"&lt;BR /&gt;  read Answer&lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt; if [ $Answer = 'n' ]&lt;BR /&gt; then&lt;BR /&gt;  echo "User NOT added"&lt;BR /&gt;  else&lt;BR /&gt;&lt;BR /&gt;  /usr/sbin/useradd -d /home/$USER -m -c "$FIRST $SURNAME - ($BRANCH)" -s /usr/bin&lt;BR /&gt;  /ksh -g coins -k /etc/skel/coins $USER&lt;BR /&gt;&lt;BR /&gt;  passwd $USER&lt;BR /&gt;  passwd -f $USER&lt;BR /&gt; fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;PS: just keeping a variable to indicate a valid user and negating it if any input is invalid...&lt;BR /&gt;&lt;BR /&gt;hth</description>
      <pubDate>Thu, 20 Oct 2005 09:28:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935228#M740331</guid>
      <dc:creator>Orhan Biyiklioglu</dc:creator>
      <dc:date>2005-10-20T09:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935229#M740332</link>
      <description>line 48 should be &lt;BR /&gt;&lt;BR /&gt;if $VALIDUSER&lt;BR /&gt;&lt;BR /&gt;sorry for the typo.</description>
      <pubDate>Thu, 20 Oct 2005 09:32:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935229#M740332</guid>
      <dc:creator>Orhan Biyiklioglu</dc:creator>
      <dc:date>2005-10-20T09:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935230#M740333</link>
      <description>hey that's great.&lt;BR /&gt;&lt;BR /&gt;i presume if validates true or false automatically like that.&lt;BR /&gt;&lt;BR /&gt;The other bit is great also.&lt;BR /&gt;&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;exactly what i wanted.&lt;BR /&gt;&lt;BR /&gt;11/10!</description>
      <pubDate>Thu, 20 Oct 2005 10:16:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935230#M740333</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2005-10-20T10:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935231#M740334</link>
      <description>i see it was my misplacement of 'fi' and elses that were causing my problem.&lt;BR /&gt;&lt;BR /&gt;have i written this in a stupid way? i am relative beginer.&lt;BR /&gt;&lt;BR /&gt;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'.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Oct 2005 10:20:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935231#M740334</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2005-10-20T10:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935232#M740335</link>
      <description>thanks :-)</description>
      <pubDate>Tue, 07 Feb 2006 05:59:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/4935232#M740335</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-07T05:59:57Z</dc:date>
    </item>
  </channel>
</rss>

