0

I have created a audit.ksh file which is used to clear old "*.aud" files. But when i run this file am getting below error. The strange thing is the commands inside the file works fine while executing openly in prompt.The user is in C shell.

TxxxxD01:user 55>./aud_clean.ksh
export RES_RETRY=1: 0402-026 The specified data is not a valid identifier.
TxxxxD01:user 56> echo $SHELL
/usr/bin/csh
TxxxxD01:user 57> cat aud_clean.ksh
cd /oracle/SID/saptrace/audit
find *.aud -mtime +3 -exec rm {} \;
TxxxxD01:user 60> cd /oracle/SID/saptrace/audit
TxxxxD01:user 61> find *.aud -mtime +3 -exec rm {} \;
TxxxxD01:user 62>
  • You should also look into why your shell initialization files are pulling in /etc/environment; that should be unnecessary. – Jeff Schaller Apr 25 at 11:14
2

Your ksh shell script does not have a sh-bang line indicating that it should be run with ksh, so your csh shell is attempting to run it (with /bin/sh, which is the one complaining about the export RES_RETRY=1 syntax). Add a sh-bang line of

#!/bin/ksh

to the top of the script.

  • The csh shell executes a shebang-less script using sh (Which shell interpreter runs a script with no shebang?). There may be a shell initialisation file that sh executes that has an error, but I don't know what file that would be (~/.profile should only be read for login shells), $ENV may possibly be defined though. – Kusalananda Apr 25 at 10:35
  • Good point; and RES_RETRY appears to be a DNS configuration item, which shouldn't be getting pulled into shell initialization files (and clearly isn't part of the ksh script). – Jeff Schaller Apr 25 at 10:54
  • No, csh will execute non-shebanged scripts with /bin/sh, not with csh. The problem is that the export VAR=val syntax is not supported in some ancient shells -- you have to write VAR=val; export VAR there. Your solution of adding the #! /bin/ksh shebang works, because ksh does support that syntax. But the rationale is off. – mosvy Apr 25 at 11:11
  • Thank you to mosvy and Kusalananda; I've updated the answer to clarify the behavior. – Jeff Schaller Apr 25 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.