Use SCP command to implement file upload code in Shell _linux shell

Source: Internet
Author: User
Tags bz2 file upload pack svn file permissions scp command

Since SSH can execute remote command, the FTP software is also gradually less used.

Every time the server code is updated, all want to pack, upload, login to the server to modify file permissions, update Cache, and so on, slow and error prone, so make a script, a help me to fix, I lit a cigarette sitting in front of the computer, or play a while "Plant vs Zombies" what, leisurely!

Ps:ant and phing users, you can ignore ... I just like to play Shell.

Copy Code code as follows:

#!/bin/sh

Home= '/cygdrive/d/public_html/myproject '

# # Pack The local code first
# # Exclude the following files: *.svn, *.bat, upload.sh, cache
# # If you need to exclude a lot of files, you can use the parameters--exclude-from=file
# # Writes a line of files to file
CD $HOME
Tar jcf tmp.tar.bz2 * \
--exclude=*.bat \
--EXCLUDE=*.BZ2 \
--exclude=*.gz \
--EXCLUDE=.SVN \
--exclude=cache \
--exclude=upload.sh \

# # upload files via SCP
SCP tmp.tar.bz2 user@your.host.com:/home/public_html/myproject/tmp.tar.bz2

# # Execute remote SSH command
# # Here's another script executed load.sh
SSH user@your.host.com
"
Cd/home/public_html/myproject
Tar jxf tmp.tar.bz2
Chown-r Web:web *
Chmod-r 755 *
SH load.sh
Rm-f tmp.tar.bz2
"

# # Delete local files
Rm-f tmp.tar.bz2
echo "Everything is done."

# Week one by one month by Verdana
# Vim:set Expandtab tabstop=4 shiftwidth=4:

SSH I configured the automatic login, you can refer to here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.