Script that Redirect SSH output via cron

Hi,

I have a script that's being called via a crontab which is a wrapper script that creates a log for the script that gets executed. Within the script that gets executed, it also run's subscripts. I've been able to get everything to work .. but the issue is one of the subscript that goes out and does a set of remote ssh connections to run a local script on servers, the output currently is being re-directed back to a file local to the system of execution, the problem is when the cron run's I know the output is being generated but it does not redirect to the local file. The file gets generated but they're all blank. I've tried to troubleshoot each script at a time and if I run the wrapper script manually, everything works, but when cron executes the script outputs these 0byte files.

I've tried:

ssh root@$i /tmp/subscript.sh >> /local/file
ssh -n root@$i /tmp/subscript.sh >> /local/file
ssh root@$i /tmp/subscript.sh &> /local/file
ssh root@$i /tmp/subscript.sh > /local/file 2>&1

I've tried many different method but I've just been left with manually running the wrapper script few times out of the day vs. having it automated.

I don't know how else I could troubleshoot or figure a way to re-direct the output from the remote ssh connection back to a local file that works under a crontab?? Any suggestions?

To direct the result of remote script on a remote file:

ssh root@$i "/tmp/subscript.sh >> /remote/file"

To direct the result of remote script on a local file:

ssh root@$i "/tmp/subscript.sh" >> /local/file

Interesting .... I'll give this a try on Monday morning. Thanks

And loging as root through ssh is bad! :smiley:

Unfortunately this has been discussed and for now, that is the method of getting the info we need. We looked at a local service account but there were some against it. I agree, it should be a local service account and utilizing sudo for specific commands if require.