简体   繁体   中英

Script to ssh into server automatically

I'm trying to create a script to automatically log me in to a password protected server to upload a file from an ubuntu directory automatically. I am doing this for the purposes of automatically backing up a directory every hour. I already know had to add cron jobs to run my script every hour, but I don't know how to SSH, zip my directory then upload it. I don't know bash scripting very well, and in fact I was thinking it might be easier for me to use a python script. What is the best way to go about doing this?

You absolutely need public keys instead of passwords. And using bash will be far easier than python. Simply zip your file and then scp it or rsync the whole dir.

You could do this with Rsync . It supports ssh tunneling and is a very good tool for backups.

zip -R backup.zip directory && scp backup.zip username@server:destination_path

should do the job. As stated above, you should definitely use key authentication for this.

You can try to use "Twisted conch library"

Conch is an SSHv2 implementation written in Python.

There is an example here:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM