1827892 Members
1936 Online
109969 Solutions
New Discussion

how to upload using cron

 
Maaz
Valued Contributor

how to upload using cron

Dear Experts
SSH server IP: 10.2.2.10
Ftp server IP: 10.2.2.11

1,
I have to copy a file(/tmp/test.tar.gz) to the ssh server, using userid as "backadmin" and password "123" via schedule(cron). "backadmin", is the user on ssh server.
Now prblm is that I dont know how can i provide the userid/passwd in the crontab file.
So plz write me the syntax to achieve the above using cron.

05 22 * * * /usr/bin/scp /tmp/test.tar.gz 10.2.2.10:/tmp
Obvously fail.. because ssh server ask for userid/passwd

2,
I have to upload a file(/tmp/test.tar.gz) to the ftp server, using userid as "backadmin" and password "123" via schedule(cron). "backadmin", is the user on ftp server.
Now prblm is that I dont know how to ftp, and provide userid/passwd, and then upload a file, using cron.

plz help
Regards
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: how to upload using cron

Shalom Maaz,

You can't directly upload because as you point out you need a username ans password.

But if instead of the command line present you have an upload script with user name and password:

sftp ap1030@sihp8024 <<-EOF

put test_file
bye
EOF


Modify it to your hearts content.

My script above, scraped from itrc fixes the problem identified. Change ap1030 to the backadmin user, blah blah blah.

SEP


Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: how to upload using cron



This scrip may work better.

Both servers need openssh to make this work.


sftp backadmin@10.2.2.10 <<-EOF 2>/dev/null
open username passwd
cd /tmp
put /tmp/test.tar.gz
bye
EOF


SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Maaz
Valued Contributor

Re: how to upload using cron

Thanks SEP
You mean that i create a script having code you provide ... and then execute the script using cron.. isint ?
Now prblm is that my Ftp server is MS IIS server, and I cant install the ssh on MS IIS server machine.
Second ... the ssh server is running redhat ES 4 but this machine doesnt have vsftpd rpm installed.. and neither I am allowed to install the rpm... so plz provide me the script which just ssh... not the ftp.

Regards
Maaz
Valued Contributor

Re: how to upload using cron

Oh I got it "sftp" doesnt required "ftp server".. So plz dont consider the "Second part" of my previous post.. plz dont consider the following

Second ... the ssh server is running redhat ES 4 but this machine doesnt have vsftpd rpm installed.. and neither I am allowed to install the rpm... so plz provide me the script which just ssh... not the ftp


Ok SEP, as per your instruction, I create a script, and put the following code in it

#!/bin/bash
sftp backadmin@10.2.2.10 <<-EOF 2>/dev/null
<123> ###password of user "backadmin"
cd /home/backadmin
put /tmp/test.tar.gz
bye
EOF
Now when I execute the script it succesfuly upload the test.tar.gz into the /home/backadmin ... but it ask for "password".. i.e i cant use/run this script using cron

Plz help
Huc_1
Honored Contributor

Re: how to upload using cron

Have a look/read at
man netrc
This is a way to pass user/pass etc to (ftp,sftp..etc).

You could create a user that is only used for this purpose.

Enjoy life

Jean-Pierre Huc
Smile I will feel the difference
Maaz
Valued Contributor

Re: how to upload using cron

Thanks Dear SEP, and HUC for help.
SEP, I think when the Destination server is sshd, then the best I found is "scp", with "host base authentication" to upload the file, using script, and execute the script using cron.
Dear HUC, I will try to follow your instruction

Thanks Once again
Regards
Needee