Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I code an automatec job execution

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I would like the following job to run via root cron ;
LOGF="/usr/local/erp/oraerp/ss.log"
su - newuser -c "date
for fil in `ls /mydir/*.sh`
do
sh $fil >> $LOGF
done
date"

The job must do the following steps ;
1 Show date
2. for each file in the mydir
executre the file
3. Show date

I get this error ;
ksh: syntax error at line 2 : `/mydir/st2.sh' unexpected
 
execute the script the following way

sh -x myscript

what is the output?

Regards
-- Franz
Sorry I'm not a native spaeker, I'm from Munich, Germany - "Home of the Whopper", oh no, "Home of the Oktoberfest" ;-)
 
The problem is not /mydir/st.sh becuase I can run it fine by itself.
The problem is in the loop somewhere where it seems to read the first entry only. Note that the scripts is trying to do a loop within an su session.
 
Why are you doing it that way. Why not put the script in a wrapper and call the wrapper from your su? Or am I missing something (well, it is Friday afternoon!).
 
Try to substitute the " character with a ' wich is equivalent.
The problem is in the interpretation of $ symbols
 
I agree with KenCunningham - I think the problem is that &quot;su - <name> -c&quot; objects to getting a multi-line command. Hopefully, if you put the script into a file that is then called by su it will all work.

I'm also slightly worried by the error message coming from from ksh when you call the /mydir/*.sh scripts as &quot;sh $fil&quot;.

Good luck.
 
Nope, there aren't any problem in the multi line but, if it sounds better tison can put all the command in a variable and then execute:
su - user -c &quot;$variable&quot;
 
I confirm my previous post, just tried what suggested and works.
Substitute &quot; with '
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top