It is currently Tue, 07 Dec 2021 03:33:09 GMT



 
Author Message
 executing /bin/sh script in a /bin/csh login

I am initiating a shell script that goes out to various UNIX hosts to
get system info.  I want to run the shell as bourne shell for the sake
of uniformity.  

I initiate a shell script#1 on the local host.  Script#1 will do an rsh
to the remote host, the remote host will mount itself to the local host
and then call another script (script#2) that resides on the local host.  

The default ROOT login for the remote host is /bin/csh.  The problem is
that when i login to the remote host it will not read the script that
has been written in bourne shell.  At the beginning of script#1 and
script#2 i use the "#! /bin/sh" syntax.  
The remote host will not read the       if [ ! -d $MOUNT_PT ]
                                                then  
                                                /bin/mkdir $MOUNT_PT
                                                fi

The errors that i get are as follows:

Remote: csns2
Missing ].
then: Command not found.
mkdir: /admin_mnt: File exists
fi: Command not found.
MOUNT_PT=/admin_mnt: Command not found.
export: Command not found.
HOST=csns2: Command not found.
export: Command not found.

I would appreciate any help that I could get.  I did read the
comp.unix.shell FAQ and did see some differences btw. csh and sh but
could not seem to get an answer to my problem.  
Thanks in advance.
rolf

SCRIPT #1

#! /bin/sh
   ...
   if [ "$OS" = SunOS ] && [ "$OSVER" = 4 ]
    then
      rsh $HOST "
       echo "Remote: $HOST"
     if [ ! -d $MOUNT_PT ]
     then  
        /bin/mkdir $MOUNT_PT
      fi
      /usr/etc/mount -t nfs nordic:$MOUNT_PATH $MOUNT_PT
      cd $MOUNT_PT
#      (setenv MOUNT_PT /admin_mnt;setenv HOST
$HOST;$MOUNT_PT/scripts/sunos_info.sh)
      (MOUNT_PT=/admin_mnt;export MOUNT_PT;HOST=$HOST;export
HOST;$MOUNT_PT/scripts/sunos_info.sh)
     cd /
      /usr/etc/umount $MOUNT_PT"
    fi
    ...

SCRIPT #2  (sunos_info.sh)

#! /sbin/sh -x
#######################################################
# FUNCTIONS
#######################################################
# disk space function for SUNOS
df_report () {
              if [ ! -d $MOUNT_PT/data/hosts/$HOST ]
              then
                mkdir $MOUNT_PT/data/hosts/$HOST
              fi

              /bin/df -t 4.2 | grep -v : >
$MOUNT_PT/data/hosts/$HOST/disk_space
              }
# END disk_space
#######################################################
df_report



 Mon, 05 Jun 2000 03:00:00 GMT   
 executing /bin/sh script in a /bin/csh login

On Thu, 18 Dec 1997 17:20:38 -0700, "David B. Maislin"

The test statement will not accept this usage of the unary operator.
There are several different solutions. The simplest is to create the
directory unconditionally, and just redirect error messages to
/dev/null like:
      /bin/mkdir $MOUNT_PT >/dev/null 2>&1

If you want to perform the test, you may do it like this:
      [ -d $MOUNT_PT ] || /bin/mkdir $MOUNT_PT

Both solutions will solve your problem.

Kind regards
Henrik Davidsen
mailto:hedor...@post6.tele.dk



 Tue, 06 Jun 2000 03:00:00 GMT   
 executing /bin/sh script in a /bin/csh login

In <3499BDD6.1...@nordic.geg.mot.com> "David B. Maislin" <pmais...@central1.geg.mot.com> writes:

Err... just a first glance but shouldn't that test have a semicolon after
it? All mine do....
if [ ! -d $MOUNT_PT ] ;
then  
    /bin/mkdir $MOUNT_PT
fi

--
Graeme Griffiths - Discreet Logic (Newbury, UK)
Disclaimer: I do not speak for anyone but myself and I do that badly.
Mail: gra...@discreet.co.uk
Spam: All unsolicited mail will be reported, and billed for my time.



 Tue, 06 Jun 2000 03:00:00 GMT   
 executing /bin/sh script in a /bin/csh login

| "David B. Maislin" <pmais...@central1.geg.mot.com> writes:
|
|> I am initiating a shell script that goes out to various UNIX hosts to
|> get system info.  I want to run the shell as bourne shell for the sake
|> of uniformity.  
|
|> I initiate a shell script#1 on the local host.  Script#1 will do an rsh
|> to the remote host, the remote host will mount itself to the local host
|> and then call another script (script#2) that resides on the local host.  
|
|> The default ROOT login for the remote host is /bin/csh.  The problem is
|> that when i login to the remote host it will not read the script that
|> has been written in bourne shell.  At the beginning of script#1 and
|> script#2 i use the "#! /bin/sh" syntax.  
|> The remote host will not read the       if [ ! -d $MOUNT_PT ]
|>                                                   then  
|>                                           /bin/mkdir $MOUNT_PT
|>                                                   fi
|
|
| Err... just a first glance but shouldn't that test have a semicolon after
| it? All mine do....
| if [ ! -d $MOUNT_PT ] ;
| then  
|     /bin/mkdir $MOUNT_PT
| fi

If you have access to a UNIX computer, give it a try.  ";" is a logical
end of line, and at end of line it's redundant.

I don't see anything wrong with the syntax - it's conceivable that some
shell implementation could have trouble with  "test ! -d xxx", but in
practice I think all can handle that.  To test that, reverse the sense
of the test -
  if test -d $MOUNT_PT
  then
       :
  else
       /bin/mkdir $MOUNT_PT
  fi

Assuming syntax is OK, and assuming MOUNT_PT is defined as expected
(verify this using "echo"), we have to assume the poster's surmise is
correct and root is executing the script with csh.  (It would eliminate
a lot of useless speculation if people would post the actual error
messages if any, rather than using terms like ``the remote host will
not read''.)  One thing to verify is that the script is chmod +x and
the #!/bin/sh line is right at the top.

        Donn Cave, University Computing Services, University of Washington
        d...@u.washington.edu



 Tue, 06 Jun 2000 03:00:00 GMT   
 
   [ 4 post ] 

Similar Threads

1. executing /bin/sh script in a /bin/csh login #2

2. /bin/sh, /bin/ksh crash with SIGSEGV with a huge script

3. #!/bin/sh #!/usr/bin/sh can I do both for 2 diff machines

4. /bin/ksh vs /usr/xpg4/bin/sh

5. /bin/sh and /usr/bin/ksh

6. re : /bin/sh:/bin/tar:0403-027:parameter list is too long

7. /bin/sh:/bin/tar:0403-027:parameter list is too long

8. #!/bin/sh | #!/bin/ksh ...

9. % /bin/sh -c /bin/ls -l -R ???

10. Q: Sendmail Bug using From: |/bin/tail|/bin/sh


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software