My script stops working when using crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My script stops working when using crontab
# 1  
Old 07-14-2012
My script stops working when using crontab

I have made a shell script(/bin/sh) that starts a perl script (that I haven't made my self) that's starts a ssh session. The ssh session uses a private/public key to login so no password is needed. The Perl script works perfect.

But when I put it in a cronjob (crontab) the ssh connection asks for password. This makes the scripts fail. Seems like ssh keys are not working while running in cron. Is there a process that I shall start?

This is the reason why I made the shell script to load most of my env variables( I know that cronjob starts with a slim shell) from my normal shell. I thought it was some env variable that I have missed to set. I don't have much Unix experience so not sure how I can describe the problem more. If there anything else that I have to say ask about it.

I tried to search for it but found something about ssh-agent. That should be started but didn't understand it. Also something about a keying.
# 2  
Old 07-14-2012
Is cron being invoked by the same user that has the trused keys?
# 3  
Old 07-15-2012
Quote:
Originally Posted by raiderfan1
Is cron being invoked by the same user that has the trused keys?
Yes, the crontab is run by the same user as the script works for. I put:

Code:
echo 'whoami' > whoami.txt

in the shell script to check that.
# 4  
Old 07-15-2012
  1. when using cron you have to provide the full path to any executable
  2. provide the path to the keys ssh -i /home/user/.ssh/id_rsa
This User Gave Thanks to Skrynesaver For This Post:
# 5  
Old 07-15-2012
Quote:
Originally Posted by Skrynesaver
  1. when using cron you have to provide the full path to any executable
  2. provide the path to the keys ssh -i /home/user/.ssh/id_rsa
Thanks I will try thatSmilie.

However I'm not sure if I can modify the perl script. Will it work if I just put it in my $PATH?
# 6  
Old 07-15-2012
I don't know about putting it in your path, but you could alias "ssh" to "ssh -i /whatever/path". For some reason I never got to the bottom of, ssh doesn't find my keys either on our system, so I added "alias ssh='ssh -i ~/.ssh/identity'" to my bash startup files.

Since you are using cron however, I think you may need to create a small wrapper containing just the alias + call to the perl script, and start *that* from within crontab. Or something like that ;-)
# 7  
Old 07-15-2012
Off topic (maybe).
Quote:
echo 'whoami' > whoami.txt
This will not work from cron because it needs terminal context.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (1 Reply)
Discussion started by: ash1234
1 Replies

2. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (6 Replies)
Discussion started by: ash12345
6 Replies

3. Red Hat

Script not working if crontab scheduled

Hi all, I'm working to a script with /bin/bash shebang. The script works perfectly if I run from command line. The script runs under a non root user and inside the commands are set with sudo command in a such a way they can be run under root, for example (first rows of the script):... (5 Replies)
Discussion started by: idro
5 Replies

4. UNIX for Dummies Questions & Answers

Script is not longer working in the crontab

This is the crontab it is supossed to be running everyday but it didnt 5 0 * * * /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 Inside the above script connects to a database and extract data to a flat file, manually i run the script at about 2 a.m. and Works OK,... (6 Replies)
Discussion started by: alexcol
6 Replies

5. Shell Programming and Scripting

Script not working in crontab

Hi I have created a script. Which i have configured in cron to make it run in every 2 min. But script is not running. If I checl the cron log at /var/cron/log .it shows its running in every 2 min. Below is the command which i configured in crontab. But I am not able to find the way so that... (9 Replies)
Discussion started by: nandan8a
9 Replies

6. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

7. Shell Programming and Scripting

Script stops working after copying it

Hi all, When I cp a script, this section of the code stops reading from a file. if ; then while read dirtoclean do DIRSTOCLEAN=${DIRSTOCLEAN}' '$dirtoclean done < ${BASEDIR}test.conf fi ${DIRSTOCLEAN} doesn't return anything, even though it will work right before... (6 Replies)
Discussion started by: nicksantos1
6 Replies

8. SuSE

USB mouse stops working

I have 64bit 11.1 installed on a clone. The Logitech LX3 mouse stops working sometimes, forcing a reboot. The LED under the mouse goes dark when this happens. A normal ps/2 mouse works fine, and I am certain the LX3 mouse is not defective as I have an identical one on a XP system that I swapped to... (6 Replies)
Discussion started by: stansaraczewski
6 Replies

9. UNIX for Advanced & Expert Users

ssh-keygen stops working

Hey guys, I was using ssh-keygen settings for a long time to login on remote machines without password. 2 days back it suddenly stops working, i tried by reset all ssh-keygen setting but it not works. what could be the reason of this issue and how can i resolve this? (2 Replies)
Discussion started by: RohitKJ
2 Replies

10. Solaris

Solaris 10 - init stops working

I have a really strange issue on Solaris 10 running on v490. I'm running Oracle 10g on the box. Everything runs fine and all of a sudden I get a call from a DBA. I check and none of the Oracle processes are running. They were definitely running after the system booted and nobody stopped them. I try... (0 Replies)
Discussion started by: GKnight
0 Replies
Login or Register to Ask a Question