Solved

Running script

Posted on 2008-10-11
9
227 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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 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…

776 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