Automated SCP from a job?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automated SCP from a job?
# 1  
Old 08-30-2011
Automated SCP from a job?

Hi all -
I have a script which runs on the OS level, but refuses to run as a cron or as an Oracle job. The Script is pretty straight forward:

Code:
#!/bin/bash
username="MyUsername"
host="Remote.server"
path="Remote.directory/files/*.*"
password="MyPassword"
expect -c "
spawn /usr/bin/scp $username@$host:$path /my/directory
expect {
    "*password:*" {
        send $password\r;
        interact;
        }
    eof{
        exit
    }
}
"

Now, if I just run this from the cmd line as './MyScript.sh' it runs fine, but as soon as it runs from cron or the oracle job scheduler, it starts and copies about 100k of the file and abruptly ends on 'success'.

Im hoping a few of you may have had this issue before, and maybe a few of you are DBA's.....

Cheers
Dan

Last edited by pludi; 08-30-2011 at 05:36 PM..
# 2  
Old 08-30-2011
If you could use ssh keys instead of kludging in an insecure plaintext password with the 'expect' brute-forcing tool, you'd get much more direct return status, clearer errors, etc. That's because it's the way ssh is designed to work.

Everyone on the system may be able to see your password when that script runs.
# 3  
Old 08-30-2011
I can't unfortunately get keys installed. Alternately, this is the best way i could find to do it. Any other ideas?
Thanks.
Dan
# 4  
Old 08-30-2011
Quote:
Originally Posted by danimaltex
I can't unfortunately get keys installed. Alternately, this is the best way i could find to do it. Any other ideas?
Thanks.
Dan
What do you mean "I can't get keys installed". Anyone can setup keys unless the SSH config is locked down tightly which is not normal.

The correct and best way to do this is to use ssh public keys. Using expect like this is complicating what is already built into ssh. work smarter not harder.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automated scp using shell & expect

Hi All, I have written a script to automate scp of files. Most of the times it works fine except few cases. I want your help and suggestions to fix these failures. I have used expect & shell to do the automated scp. Below is code $ cat scp.ksh #!/bin/ksh inputfile=$1 fdest_sid=$2... (8 Replies)
Discussion started by: veeresh_15
8 Replies

2. Shell Programming and Scripting

autosys job configuration for job failure.

We need to configure autosys that when a job fails continously for 3 times, we need to call another job. Is this possible in Autosys, or can anyone advice on the alternative. (2 Replies)
Discussion started by: sangea
2 Replies

3. Shell Programming and Scripting

Cron Job Automated Email Alternatives?

Hi guys, not sure if this would be the right place for this but I dont where else it would go... I'm new to Unix too, so please bare with me :) I guess first up some background on the situation. We have some scripts that run as cron jobs which monitor and check the health, etc of our servers.... (2 Replies)
Discussion started by: BrianD
2 Replies

4. UNIX for Advanced & Expert Users

Automated SCP script passing password to preserve source file timestamp

Hi My requirement is i want to copy files from remote server to the local server and also i need to preserve the timestamp of the remote file. By using scp -p , it is working fine in the interactive call but it is not preserving he file timestamp when i use it in the non interactive scp call... (1 Reply)
Discussion started by: skumar75
1 Replies

5. Shell Programming and Scripting

Script to Start a Job after finding the Old job completed

Hi Experts, I need a script advice to schedule 12 jobs ( SAS Codes execute back ground ). Algorithem: 1. Script checks first job. 2. Finds first job is done; invoke second job. 3. finds second job is done; invoke third job. .. Request you to please assist. (3 Replies)
Discussion started by: Jerald Nathan
3 Replies

6. UNIX for Advanced & Expert Users

scp automated script

Hi Unix gurus, I am trying to create a script to automate the copying of files daily from one server to another using the scp command. --> #!/bin/ksh KEY="$HOME/.ssh/SSHKEY" if ;then echo "Private key not found at $KEY" >> $LOGFILE echo "* Please create it with \"ssh-keygen -t dsa\" *"... (5 Replies)
Discussion started by: gholdbhurg
5 Replies

7. Shell Programming and Scripting

Need logic for check automated Job work in awk or SED.

I have a Java program which will automatically trigger some scheduled job to update Db or some other work. I am tracking the jobs with log messages and finding out it is properly run or not. I want to write a script to capture it correctly on time. Say Job1 is running on 15, 30, and 45 every... (5 Replies)
Discussion started by: senthilkumar_ak
5 Replies

8. UNIX for Dummies Questions & Answers

How to insert child job under a box job?

I have this box job and it contains only one job under it which is to load a file. I want to insert a "File Watcher", "Copy File" to it? Have no clue how to do that...any help plzzz... (4 Replies)
Discussion started by: xejatt
4 Replies

9. Solaris

killing a unix job after the job process gets completed

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. Thanks... (7 Replies)
Discussion started by: dtazv
7 Replies

10. Shell Programming and Scripting

killing unix job after the job process completes

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. ... (1 Reply)
Discussion started by: dtazv
1 Replies
Login or Register to Ask a Question