![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
Try running this in a script that looks like this -
Code:
#!/bin/ksh ssh -l <user> <servername> /path/to/script/scriptname exit |
|
#5
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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" |
|||
| Google The UNIX and Linux Forums |