Solved

Running script

Posted on 2008-10-11
9
221 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
Comment Utility
verify the path to the file:

/home/blah/etc/blah1
0
 
LVL 19

Expert Comment

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

Author Comment

by:c00kie88
Comment Utility
still no good..

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

Expert Comment

by:omarfarid
Comment Utility
can you post the script and how it is called?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:c00kie88
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Did you run with sh -x?
0
 

Author Comment

by:c00kie88
Comment Utility
Hi all,

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

It fixed now,
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

772 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

12 Experts available now in Live!

Get 1:1 Help Now