Solved

Running script

Posted on 2008-10-11
9
223 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:c00kie88
  • 4
  • 3
  • 2
9 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22693955
verify the path to the file:

/home/blah/etc/blah1
0
 
LVL 19

Expert Comment

by:jools
ID: 22694041
./sh -x <script> will list the commands as they are executes, may help diagnose the problem
0
 

Author Comment

by:c00kie88
ID: 22696732
still no good..

i don't know what's wrong
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22696736
can you post the script and how it is called?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:c00kie88
ID: 22697001
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
 

Author Comment

by:c00kie88
ID: 22697015
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
 
LVL 40

Accepted Solution

by:
omarfarid earned 125 total points
ID: 22697301
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
 
LVL 19

Expert Comment

by:jools
ID: 22697651
Did you run with sh -x?
0
 

Author Comment

by:c00kie88
ID: 22736779
Hi all,

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

It fixed now,
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now