Running script

I created a script called blah1 which located under /home/blah/etc/blah1

I created another script called stuck which located under /home/blah

#!/bin/sh

BLAH1=/home/blah/etc/blah1

echo "please enter name"
read name
$BLAH1 $name

the problem is :

when i run blah1 command inside STUCK script, it said "command can't be found"

but when i run on the prompt as ./blah1 me, it works fine..

What is the problem here?

Please help
c00kie88Asked:
Who is Participating?
 
omarfaridConnect With a Mentor Commented:
I have following notes:

- you are not setting env var. like PATH

- you are using commands like expr sleep grep

If you run this script from a crontab or from another user that do not have PATH set correctly, then it will not be able to run these commands

- you are calling / running ./mkpasswd which might not be in the current dir
0
 
omarfaridCommented:
verify the path to the file:

/home/blah/etc/blah1
0
 
joolsCommented:
./sh -x <script> will list the commands as they are executes, may help diagnose the problem
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
c00kie88Author Commented:
still no good..

i don't know what's wrong
0
 
omarfaridCommented:
can you post the script and how it is called?
0
 
c00kie88Author Commented:
ok..

I have passwd script file which i store at /home/blah called script.passwd

i created another script called menu located at /home/blah

!#/bin/sh

SCRIPT=/home/blah/script.passwd

echo "enter username"
read name
`$SCRIPT shadow $name`






#!/bin/sh 
 
AWK=/usr/bin/awk
BASENAME=/bin/basename
ECHO=/bin/echo
EXPR=/usr/bin/expr
GREP=/usr/bin/grep
MV=/bin/mv
RM="/bin/rm -f"
SED=/usr/bin/sed
STTY=/bin/stty
 
 
 
SYSTEM=`uname -s`
if [ "$SYSTEM" = "Linux" ] ; then
   DATE="/bin/date +%y%H%m%M%s"
   WHOAMI=/usr/bin/whoami
elif [ "$SYSTEM" = "SunOS" ] ; then
   DATE="/usr/bin/date +%y%H%m%M%S"
   WHOAMI=/usr/ucb/whoami
else
   echo "Unidentified OS - exiting"
fi
 
 
ME=`$WHOAMI`
LOCK=/tmp/shadow.$ME
SHADOW=${1}
USER=${2}
 
NAME=`$BASENAME $0`
 
count=0
# locking code - is there still a possibility of
# a race condition here?
while [ -f $LOCK  ]  && [ $count -lt 10 ] ; do
      if [ x`cat $LOCK` != x$$ ] ; then
         count=`expr $count + 1`
         sleep 1
      fi
   done
 
   if [ -f $LOCK ] && [ x`cat $LOCK` != x$$ ] ; then
      echo "another process has a lock on the shadow file - "
      echo "if you aren't running the script then delete /tmp/shadow.$ME and try again"
      exit 3
   fi
 
 
echo $$ > $LOCK # get lock for shadow file
 
if [ $# -lt 2 ] ; then
   echo "$NAME: usage:- $NAME shadow_file_name username"
   exit 2
fi
 
 
$GREP "^${USER}:" ${SHADOW} >/dev/null 2>&1
if [ $? -ne 0 ] ; then
   echo "$NAME: there is a problem with the arguments"
   echo "      usage:- $NAME shadow_file_name username"
fi
 
 
$ECHO "Changing password for user $USER"
OK=1
while [ $OK -eq 1 ] ; do
   trap "$STTY echo" 1 2 3 15
   $STTY -echo
   $ECHO "Enter new password: \c"
   read PASSWD1
   $ECHO ""
   $ECHO "Repeat new password for confirmation: \c"
   read PASSWD2
   $ECHO ""
   $STTY echo
   trap 1 2 3 15
 
   if [ "$PASSWD1" != "$PASSWD2" ] ; then
      $ECHO "The passwords do not match, try again"
   else
      $ECHO "Changing password for user $USER"
      OK=0
   fi
done
 
 
Time=`$DATE`
SALT=`expr $Time % 100000000`
while [ $SALT -lt 10000000 ] ; do
   SALT=`expr $SALT \* 10`
done 
 
if [ "$SYSTEM" = "Linux" ] ; then
   new_pw=`/usr/bin/mkpasswd --hash=MD5 --salt=$SALT $PASSWD1`
   new_pw="\$1\$${new_pw}" # set the marker right for MD5 password on Linux 
elif [ "$SYSTEM" = "SunOS" ] ; then
   # You may need to put a path here for the Solaris mkpasswd 
   new_pw=`./mkpasswd -m MD5 $PASSWD1 $SALT` 
fi
 
 
old_pw=`grep "^${USER}:" $SHADOW | $AWK -F: '{print $2}'`
 
if [ "$old_pw" = "" ] ; then # we've got a problem here -- it's hard to replace an empty field
   set x
   $SED "s/^${USER}::/${USER}:LK:/" $SHADOW > /tmp/$$ && $MV /tmp/$$ $SHADOW
   old_pw="LK"
fi
 
$SED s:${old_pw}:${new_pw}: $SHADOW > /tmp/$$ && $MV /tmp/$$ $SHADOW
 
$RM $LOCK

Open in new window

0
 
c00kie88Author Commented:
When i run the script from prompt, it works fine

./script.passwd shadow dummy

but when i called it within another script, it hangs and gives me different error.

0
 
joolsCommented:
Did you run with sh -x?
0
 
c00kie88Author Commented:
Hi all,

I just found out that it's PATH issue..

It fixed now,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.