Script only runs first time through crontab

Hello,

I am trying to run a script through crontab and it runs the first time and then it does not run.

I tried to run a simple script (as shown below) and I see the same issue.

#!/bin/ksh
clear
echo "Good Morning, World." > /tmp/test123

Crontab Entry:

30 09 * * * /home/uhosting/test > /tmp/test123 2>&1

Any advise/comments, please?

  1. Before the /tmp... use >> instead of >
  2. If you schedule it once per day (at 9:30) then it is normal that is only run once per day :wink:
  3. Avoid to name a script "test" : "test" already is the name of a unix command ... (as well as "script" by the way ! )
  4. Don't use the same logfile inside your script and from crontab (conflicting redundancy by concurrent access )

In the script or in the crontab?

In the crontab. And get rid of the one in the script!

Andrew

Up to you, but avoid to update them both at the same time (i updated my previous post).

Thanks for the inputs, that works. Now the script that I have issue, I am trying to logon to a remote server and get a listing from a directory.

ssh -q servername 'ls -al /nim/dr/mksysb/*|grep _dr|cut -c37-90|cut -d" " -f2-8|cut -d_ -f1' > /tmp/output

the above command works fine from the command line but not through crontab

At this point I'm guessing ssh keys. You probably need to explicitly include the private key file you are using:

ssh -q -i /home/myname/.ssh/id_dsa ...

assuming the identity file is the id_dsa file.

What are you trying to get from the server? Do you have stat on the server? Could you use that to find the file information you are looking for?

Andrew

Is it possible that the commands are not found due to missing environment?

I did a echo $SHELL and added it to $PATH

That might be insufficient. All commands must be reachable via the $PATH variable.