The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Running a script with cron altamaha Shell Programming and Scripting 3 06-05-2008 05:46 AM
pwd & cd commands not working in shell script perk_bud Shell Programming and Scripting 9 04-07-2008 04:11 AM
script not working in CRON abhijeetkul Shell Programming and Scripting 5 07-13-2006 02:48 AM
running commands from script owijust Shell Programming and Scripting 2 01-09-2006 03:12 PM
Running script using cron ankurgupta Shell Programming and Scripting 4 12-12-2002 07:41 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-06-2005
Registered User
 

Join Date: Aug 2003
Location: Ireland
Posts: 269
running script in cron - with ssh commands - not working

I ran an ssh command to run a script on a remote server

ssh -l <user> <servername> /path/to/script/scriptname

This works fine - and the script is executed correctly.

However - I put this command into a script, that I want to run from cron every hour, to execute the file on the remote server every hour, but the process appears to hang... I can see the process but it is not doing anything. It only takes 3-4 seconds to run from command line but doesnt do anything when cron submits it:
root 16528 16527 0 14:46:00 ? 0:00 /usr/bin/ksh /<pathtoscript>/<script>
root 16527 233 0 14:46:00 ? 0:00 sh -c /<pathtoscript>/<script> > /dev/null
root 16532 16528 0 14:46:00 ? 0:00 ssh -l <user> <server> //<pathtoscript>/<script>


This just hangs.... Any ideas?
Reply With Quote
Forum Sponsor
  #2  
Old 05-07-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
Have you tried to debug this? Check out your cron log. For every job that is executed, an entry is made, along with the pid of the process that is spawned for this job. search for the entry of the cronjob and then the corresponding process. i.e

root 13151 c Mon May 2 23:55:00 IST 2005
CMD: /opt/cron/load.sh
root 13151 c Mon May 2 23:55:00 IST 2005 rc=2

The cronjob specified above has failed.

Can you check some entries like that in your cron logs?

If the cron job goes through, then the last rc=[errno] will not be there.

With ssh, important things to check:
1. is the cronjob maintained for the correct user
2. is the key maintainence done on remote end (cron will not allow user interaction and the login will have to be key based authentication)

Last edited by blowtorch; 05-07-2005 at 01:58 AM.
Reply With Quote
  #3  
Old 05-07-2005
Registered User
 

Join Date: Aug 2003
Location: Ireland
Posts: 269
Thanks for looking in to this for me.. Still havent found the issue yet..

I checked the cron log:
> CMD: /pathtoscript/script.sh 2>/dev/null
> root 515 c Sat May 7 13:33:00 2005
< root 513 c Sat May 7 13:33:00 2005

Only when I kill the first ssh script that is trying to run - is the cron log updated again. I waited 5 mins before killing the script that wasnt doing anything, then cron log got this entry:

< root 515 c Sat May 7 13:33:53 2005 rc=143


My crontab is for my root user, which can run the script from the command line but not in cron. Key Maintainance, I think this is done from my end. I generated the keys and sent the public key to the others servers authorized_keys file. It works from command line and doesnt require password to be entered. This is why I dont know why cron cannot run it.

Any other ideas?
Reply With Quote
  #4  
Old 05-07-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
Try running this in a script that looks like this -

Code:
#!/bin/ksh
ssh -l <user> <servername> /path/to/script/scriptname
exit
Instead of the ssh command, use the script in the cron. It may be that cron is using /bin/sh to run commands, while you are running this from ksh. It should not really matter, but sometimes it does.
Reply With Quote
  #5  
Old 05-08-2005
Registered User
 

Join Date: Aug 2003
Location: Ireland
Posts: 269
This is what script looks like - I think I am already going what you are asking...

#!/usr/bin/ksh

current_date=`date '+%Y%m%d'`
date_time=`date '+%Y%m%d %H:%M'`

### Execute remote Scripts ###

ssh -l <user> <servername> "/path/to/script/scriptname"
ssh -l <user> <servername2> "/path/to/script/scriptname"
ssh -l <user> <servername3> "/path/to/script/scriptname"
ssh -l <user> <servername4> "/path/to/script/scriptname"
ssh -l <user> <servername5> "/path/to/script/scriptname"
ssh -l <user> <servername6> "/path/to/script/scriptname"
Reply With Quote
  #6  
Old 05-08-2005
Registered User
 

Join Date: Oct 2002
Posts: 676
You said you are using root's cron. Does this mean you have public-key authentication set up as root?

When you run the script from the command line are you running it as root also or another user?
Reply With Quote
  #7  
Old 05-08-2005
Registered User
 

Join Date: Aug 2003
Location: Ireland
Posts: 269
Yes - I have public-key authentication set up as root.
However - the user I am running the script as on the other server is not called root. ie. Root on my server, user1 on the other server

I run the ssh script from command line on my server as root user and it works fine. (ssh -l <user1> <servername> "/path/to/script/scriptname"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0