Script using scp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script using scp
# 1  
Old 05-12-2015
Script using scp

Hello,
I am an student trying to make his final project and I wanna make a script to transfer a file using scp. The problem is that I need that executes when the computer starts (before session login), Ive tried this, if I execute it when im logged in it works, but not when the computer starts:

Code:
#!/bin/sh

scp /path/to/local/targetfile.txt remoteuser@remotehost:/path

Thanks for replys and sorry for my bad english.

Last edited by Corona688; 05-12-2015 at 02:38 PM..
# 2  
Old 05-12-2015
What is your system? Do you have cron?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-12-2015
Hello Corona688, I am gonna tell you what my project consists of:

We have a script that checks from a remote DB a value (0 or 1). If a laptop is stole (1) if not (0).

If 1: Ubuntu client makes a photo (when computer starts) and calls another script to send the photo to the server.
If 0: Ubuntu doesn't do the photo.

The problem came when we trying to send the photo, it doesn't work. If we execute it when we are logged in it works perfectly. We have been trying to solve this for like 1 week and no results. We dont wanna use cron. Thanks.
# 4  
Old 05-12-2015
I presume you have key-based authentication set up so it doesn't ask for a password...

If you're logged in, it finds the key in ~/.ssh/ by itself.

If you're not logged in, it will need to be told where the keys are with -i identityfile. It will need to have the right permissions for whatever user it's running as.

If you're not running it with cron, what are you running it with? Have you put it in as a system service or some such?
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 05-12-2015
Nice, it could be the problem, can you make a simple example of -i identityfile?
Thanks.
# 6  
Old 05-12-2015
scp -i /path/to/identityfile /path/to/local/targetfile.txt remoteuser@remotehost:/path

What /path/to/identityfile is depends on what your identity file is. It will need to be owned by whatever user you're running it as, and chmod 0600, and in a folder also owned by it set 0700.
# 7  
Old 05-12-2015
we tried:

Code:
scp -i /home/alumne/.ssh/id_rsa /00000005.jpg furts@192.168.12.235:/

It returns permission denied. We gave chmod 0600 to file and 0700 to directory.

We are executing the script as system service.

THanks.

Last edited by Don Cragun; 05-12-2015 at 04:34 PM.. Reason: Add CODE and ICODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

2. Shell Programming and Scripting

scp script with MD5

I have more than one file in my directory & I want to SCP them all with MD5 verification of local & remote file, Problem is that the script gets stop after scp one file. Below is the code. #!/usr/bin/bash cd /application/datafolder/my/ ls > my_file_list.txt while read fname do ... (7 Replies)
Discussion started by: m_raheelahmed
7 Replies

3. Shell Programming and Scripting

scp using script

Hi all, I want to setup scp script for copying files to remote server. I did google and all refereed expect, but the script failed to work. Please lead me to some useful link or piece of script. Thanks in advance, (8 Replies)
Discussion started by: nrjrasaxena
8 Replies

4. Shell Programming and Scripting

Using SCP in a script

I need to use scp command in a script, and it should not prompt me for the password. for eg: scp $a <i.p address>: After executing this it is asking the password for that ip address. Is to possible to prevent it ?..ie initialising the password initially or somthing lik tha? (5 Replies)
Discussion started by: sandy88
5 Replies

5. Shell Programming and Scripting

SCP Failing - In Script

I create a file that may contain several full path name files on a remote Linux that are to be copied. This file, called AWKOUTPUT is created from another script. It contains: X/picture1.png The script is very simple ------------------------------------------- REMOTEDIR="/var/CC/Stuff"... (4 Replies)
Discussion started by: mohrsville12
4 Replies

6. Shell Programming and Scripting

scp script help

need help on this scenario: serverA:" Under /etc there are directories like 20090908 20090909 20090910 etc.. a. I like to go to 20090909 (for example) and look for filename.. Say abx.* files.. b. I will scp this to another server 9serverB and the directory should be like this... (4 Replies)
Discussion started by: lhareigh890
4 Replies

7. Shell Programming and Scripting

scp using script

Hi, I have to copy a file from one server to another server daily using a script.How can i perform this operation. Can somebody help with the code. Regards, Ahamed. (1 Reply)
Discussion started by: ahamed
1 Replies

8. Linux

Need SCP script equivalent to FTP script .

Hi, Currently i'm using the folllowing FTP acript and its working. echo "open $server" > ftp_file echo "user $user $password" >> ftp_file echo "cd $remote_dir" >> ftp_file echo "lcd $local_dir" >> ftp_file echo "put $file">> ftp_file echo "bye" >> ftp_file ftp -nv < ftp_file I've... (1 Reply)
Discussion started by: vickramshetty
1 Replies

9. Shell Programming and Scripting

scp script for doing sftp

Hi, I have to do SFTP from Linux machine to Salaries SFTP folder. Using psftp I got the following fingur print and I know using scp I can go the sftp transfer. But I believe I need public key file generated. Can some one pls let me know how to generate the public file using following finger... (1 Reply)
Discussion started by: iamakshay
1 Replies

10. Shell Programming and Scripting

Scp script

Does anyone have a good scp script that i could modify to will bring up a menu of what files are on a host server and then allows you to input the path to the remote server all on Solaris 10? (0 Replies)
Discussion started by: soupbone38
0 Replies
Login or Register to Ask a Question