Solved

Running script

Posted on 2008-10-11
9
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:omarfarid
ID: 22696736
can you post the script and how it is called?
0
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

623 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