The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 08:46 AM
pwd & cd commands not working in shell script perk_bud Shell Programming and Scripting 9 04-07-2008 07:11 AM
script not working in CRON abhijeetkul Shell Programming and Scripting 5 07-13-2006 05:48 AM
running commands from script owijust Shell Programming and Scripting 2 01-09-2006 06:12 PM
Running script using cron ankurgupta Shell Programming and Scripting 4 12-12-2002 10:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-06-2005
frustrated1 frustrated1 is offline
Registered User
  
 

Join Date: Aug 2003
Location: Ireland
Posts: 278
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?
  #2 (permalink)  
Old 05-07-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 04:58 AM..
  #3 (permalink)  
Old 05-07-2005
frustrated1 frustrated1 is offline
Registered User
  
 

Join Date: Aug 2003
Location: Ireland
Posts: 278
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?
  #4 (permalink)  
Old 05-08-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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.
  #5 (permalink)  
Old 05-08-2005
frustrated1 frustrated1 is offline
Registered User
  
 

Join Date: Aug 2003
Location: Ireland
Posts: 278
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"
  #6 (permalink)  
Old 05-08-2005
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
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?
  #7 (permalink)  
Old 05-09-2005
frustrated1 frustrated1 is offline
Registered User
  
 

Join Date: Aug 2003
Location: Ireland
Posts: 278
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"
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0