running script in cron - with ssh commands - not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting running script in cron - with ssh commands - not working
# 1  
Old 05-06-2005
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  
Old 05-07-2005
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 05:58 AM..
# 3  
Old 05-07-2005
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  
Old 05-08-2005
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  
Old 05-08-2005
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  
Old 05-08-2005
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  
Old 05-09-2005
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"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Commands not working with ssh remote login

Hi Friends, I am unable to run our application commands on remote server using ssh (passwordless login enabled). But the same command running with telent perl script. please suggest. SSH: C:/bin>ssh -l monitor tl04cp01 exec "/home/monitor/123" /home/monitor/123: viewlog: not found. ... (7 Replies)
Discussion started by: suresh3566
7 Replies

2. Shell Programming and Scripting

Ssh - running commands on remote server

Hi, I am trying to run commands on a list of servers that I can ssh to and just want to know if there is a 'cleaner' way of doing this. At the moment, I am doing as below. Is there a way that I can escape the double quote differently? If a use a single quote to enclose the commands that I... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. Shell Programming and Scripting

Running Commands on a Remote Linux Server over SSH

Hello, I'm trying to create a ksh script to ssh to a remote server, enter the password and a couple commands. For security reasons I have changed the login, password and ip in my example. #!/bin/ksh ssh -t -t username@12.5.5.3 << EOF password cd bin pwd EOF When I run it. It... (5 Replies)
Discussion started by: seekryts15
5 Replies

4. Shell Programming and Scripting

Crontab - entry not working , cron job not running

I have put a cron entry in oracle user for taking hot backup every wednesday@ 2.30 AM and have given the cron entry 30 02 * * 3 /u01/vijay/hotbackupcron 2>&1 >> /u01/vijay/hotbackup.log also find below the script inside hotbackupcron, i have put in env variables as well ... (13 Replies)
Discussion started by: vijaymec50
13 Replies

5. Shell Programming and Scripting

How to automatically run commands after SSH and SUDO not working?

I'm working on a script to SSH and SUDO as (sap user sidadm) then automatically run commands that the sidadm user can run such as R3trans -v, tp, etc.. I can SSH without password and SUDO.. but the commands don't run after I SSH and SUDO to the sidadm user...here is the commands that I've... (2 Replies)
Discussion started by: icemanj
2 Replies

6. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

7. Shell Programming and Scripting

Getting issue while running it from cron while manually working fine

Hello, I am working one one script where I am using the below code which is using to connect with MKS client when I run my script manually it works effiecently i.e. it connects with MKS client but when I run it from CRON it doesn't connect. 1)Can some one tell when it is running from cron... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

8. Shell Programming and Scripting

Running script and commands through SSH

Hello All, I am trying to run some simulations through SSH from my mac on our university SOLARIS system. My problem is that whenever I want to execute a command I get an error which says "Invalid argument". Maybe I should explain more what I want to do and what I did. Firstly I installed a... (10 Replies)
Discussion started by: Apfik
10 Replies

9. Shell Programming and Scripting

Running php from cron - working up to a point

Hi there, I am struggling to try and work out what is going wrong with a cron job i have running daily which opens up an imap mailbox and extracts a rar file to a directory on the web server. The script works ok when run manually, and when it is running from cron, I can see that it opens up the... (2 Replies)
Discussion started by: nicky77
2 Replies

10. Shell Programming and Scripting

Cron job giving error while running SSH command

Hi All, The script which i am using to SSH to remote server is working fine when i run is using ./ but when cron runs it it gives error that "ssh: not found" please help!!! (3 Replies)
Discussion started by: visingha
3 Replies
Login or Register to Ask a Question