Install unzip CT in Linux
Trusted CT is said to be a highly interactive scripting language. I wanted to install it and try it. I didn't expect it to make me tangle with it for two days. It was just because the trusted CT relied on TCL, however, in Linux systems, Tcl is not installed on its own and must be manually installed.
Secondary CT version 5.43
Http://download.chinaunix.net/download/0003000/2845.shtml
TCL 8.4.19
Http://sourceforge.net/projects/tcl/files/Tcl/8.4.19/tcl8.4.19-src.tar.gz/download
Download two packages and decompress them separately.
1. Install TCL first
Go to the Tcl decompress directory and enter the Unix directory
#./Configure
# Make
# Make install
2. install secondary CT later
Go to the unzip CT directory
#./Configure-- With-tclinclude =/Usr/src/tcl8.4.19/generic/-- With-tclconfig=/Usr/local/lib/
# Make
# Make install
Complete, test
# CT
Expect1.1>
Expect1.1>
Everything OK
2. Upgrade script
Upgrade previous versions and add support for password input from the command line, tips for uploading success or failure of those machines
for O & M, it is very hard to manage multiple machines at the same time. In particular, if cdn o & M needs to upload a file to 1000 machines, it is very difficult to upload files one by one manually. Therefore, I wrote a small Program to batch SCP files to multiple machines.
CT is used here:
CT is used in this program to help automatically enter the SCP password. CT is mainly used to automate the process of manual interaction, this batch deployment system for O & M, batch unattended installation, batch command execution, batch upload and download
modern shell provides minimum control (start, stop, and so on. The interaction feature is left to the user. This means that you cannot run some programs without interaction, such as passwd. Some programs can be run without interaction, but the flexibility is largely lost, such as fsck. This indicates that the construction logic of UNIX tools is starting to have problems. CT just fills in some of the cracks and solves some problems that have existed in the Unix environment for a long time.
Expect uses TCl as the core language. In addition, CT can be used no matter whether the program is interactive or non-interactive.
1. multi_scp_upload.sh Source code
#! /Bin/bash
# Author: yifangyou
# Create time: 2011-05-17
# Used to batch upload files or directories to the specified directory of the target machine through SCP
# Configuration file format:
# Ssh_hosts = ("1.1.1.1" "2.2.2.2 ")
# Ssh_ports = ("22" "22"). The default value is 22, or the number is less than ssh_hosts. Use the default value.
# Ssh_users = ("root" "root"). The default value is root, or the number is smaller than ssh_hosts. Use the default value.
# Ssh_passwords = ("323" "222") can be set to the default value. If the default value is set to ssh_hosts, enter the value through the command line.
# Run sh multi_scp.sh conf_file_path file target
If [-z "$3"]
Then
Echo "Sh multi_scp.sh conf_file_path file target ";
Exit;
Fi
Default_ssh_user = "root"
Default_ssh_port = "22 ";
# Upload shell script file path
Scp_upload = scp_upload.sh
# Configure file path
Conf_file = $1
# Then upload file path
Scp_file = $2
# Remote hosttarget file or dir path
Scp_target = $3
# Determine whether the conf_file configuration file exists
If [! -E "$ conf_file"]
Then
Echo "$ conf_file is not exists ";
Exit;
Fi
# Determine whether scp_file is a file or directory
If [! -E "$ scp_file"] & [! -D "$ scp_file"]
Then
Echo "$ scp_file is not exists ";
Exit;
Fi
# Read configure file
Source $ conf_file
# If the password is not provided in the configuration file, enter
If ["$ {# ssh_passwords [@]}" = "0"] | ["$ {# ssh_passwords [@]}"-lt "$ {# ssh_hosts [@]} "]
Then
Read-P "Please input password:"-S default_ssh_password
Fi
Success_hosts = "";
Fail_hosts = "";
For (I = 0; I <$ {# ssh_hosts [@]}; I ++ ))
Do
# Remote SSH host
Ssh_host =$ {ssh_hosts [$ I]};
# Remote SSH port
Ssh_port =$ {ssh_ports [$ I]};
If ["$ ssh_port" = ""]
Then
Ssh_port = $ default_ssh_port;
Fi
# Remote SSH user
Ssh_user =$ {ssh_users [$ I]};
If ["$ ssh_user" = ""]
Then
Ssh_user = $ default_ssh_user;
Fi
# Remote SSH Password
Ssh_password =$ {ssh_passwords [$ I]};
If ["$ ssh_password" = ""]
Then
Ssh_password = $ default_ssh_password;
Fi
Echo "[" 'date + "% F % t" '"] (SCP-r $ scp_file $ ssh_user @ $ ssh_host: $ ssh_port: $ scp_target) start"
# SCP file or dir
/Usr/bin/empty CT scp_upload.sh "$ ssh_host" "$ ssh_port" "$ ssh_user" "$ ssh_password" "$ scp_file" "$ scp_target"
If ["$? "-EQ" 0 "]
Then
Success_hosts = "$ success_hosts, $ ssh_host"
Else
Fail_hosts = "$ fail_hosts, $ ssh_host"
Fi
Echo "[" 'date + "% F % t" '"] (SCP-r $ scp_file $ ssh_user @ $ ssh_host: $ ssh_port: $ scp_target) end"
Echo ""
Done
Echo "success_hosts = [$ success_hosts]"
Echo "fail_hosts = [$ fail_hosts]"
2. scp_upload.sh Source Code
#! /Usr/bin/CT
# Author: yifangyou
# Create time: 2011-05-17
# Host
Set scphost "[lindex $ argv 0]"
# Ssh port
Set port "[lindex $ argv 1]"
# SSH user name
Set scpuser "[lindex $ argv 2]"
# SSH Password
Set scppw "[lindex $ argv 3]"
# File name or directory to be uploaded
Set file "[lindex $ argv 4]"
# Name or directory of the file to be uploaded to the remote machine
Set target "[lindex $ argv 5]"
Spawn SCP-r-p $ port $ File $ scpuser @ $ scphost: $ Target
# Set the timeout time to prevent remote machine firewall from being suspended.
Set timeout 30
CT {
# Respose: "root@1.2.3.4s password:", automatically enter the password
"* Password *"{
Set timeout 30
Send "$ scppw"
}
# The first connect will respose "are you sure you want to continue connecting (Yes/No )? Yes"
"* Yes *"{
Set timeout 30
Send "yes"
Set timeout 30
Login CT "* password *"
Set timeout 30
Send "$ scppw"
}
Busy {send_user "<error: Busy>"; Exit 1 ;}
Failed {send_user "<error: Failed>"; Exit 2 ;}
Timeout {send_user "<error: timeout>"; Exit 3 ;}
}
# Permission denied not try again, Return Error Information
Set timeout 30
CT {
"* Denied *"{
Send_user "<error: Permission denied>"
Exit 4
}
"* No such file *"{
Send_user "<error: no such File>"
Exit 5
}
Busy {send_user "<error: Busy>"; exit 6 ;}
Failed {send_user "<error: Failed>"; exit 7 ;}
Timeout {send_user "<error: timeout>"; exit 8 ;}
}
Exit 0
3. Configuration File Format: SCP. conf
# Ssh_hosts = ("1.1.1.1" "2.2.2.2 ")
# Ssh_ports = ("22" "22") # Wheen port_num # Ssh_users = ("root" "root") # Wheen user_num # Ssh_passwords = ("323" "222") # Wheen password_num 4. Run the code
Find a machine that can be connected to the machine to be uploaded and install the secondary CT (you can use the secondary CT command to test whether it has been installed)
Put scp_upload.sh, multi_scp_upload.sh, and SCP. conf in the same directory and run multi_scp_upload.sh.
Trusted CT is said to be a highly interactive scripting language. I wanted to install it and try it. I didn't expect it to make me tangle with it for two days. It was just because the trusted CT relied on TCL, however, in Linux systems, Tcl is not installed on its own and must be manually installed.
Secondary CT version 5.43
Http://download.chinaunix.net/download/0003000/2845.shtml
TCL 8.4.19
Http://sourceforge.net/projects/tcl/files/Tcl/8.4.19/tcl8.4.19-src.tar.gz/download
Download two packages and decompress them separately.
1. Install TCL first
Go to the Tcl decompress directory and enter the Unix directory
#./Configure
# Make
# Make install
2. install secondary CT later
Go to the unzip CT directory
#./Configure-- With-tclinclude =/Usr/src/tcl8.4.19/generic/-- With-tclconfig=/Usr/local/lib/
# Make
# Make install
Complete, test
# CT
Expect1.1>
Expect1.1>
Everything OK
2. Upgrade script
Upgrade previous versions and add support for password input from the command line, tips for uploading success or failure of those machines
for O & M, it is very hard to manage multiple machines at the same time. In particular, if cdn o & M needs to upload a file to 1000 machines, it is very difficult to upload files one by one manually. For this reason, I wrote a batch SCP file to a small program on multiple machines.
CT is used here:
CT is used in this program to help automatically enter the SCP password. CT is mainly used to automate the process of manual interaction, this batch deployment system for O & M, batch unattended installation, batch command execution, batch upload and download
modern shell provides minimum control (start, stop, and so on. The interaction feature is left to the user. This means that you cannot run some programs without interaction, such as passwd. Some programs can be run without interaction, but the flexibility is largely lost, such as fsck. This indicates that the construction logic of UNIX tools is starting to have problems. CT just fills in some of the cracks and solves some problems that have existed in the Unix environment for a long time.
Expect uses TCl as the core language. In addition, CT can be used no matter whether the program is interactive or non-interactive.
1. Source Code of multi_scp_upload.sh
#! /Bin/bash
# Author: yifangyou
# Create time: 2011-05-17
# Used to batch upload files or directories to the specified directory of the target machine through SCP
# Configuration file format:
# Ssh_hosts = ("1.1.1.1" "2.2.2.2 ")
# Ssh_ports = ("22" "22"). The default value is 22, or the number is less than ssh_hosts. Use the default value.
# Ssh_users = ("root" "root"). The default value is root, or the number is smaller than ssh_hosts. Use the default value.
# Ssh_passwords = ("323" "222") can be set to the default value. If the default value is set to ssh_hosts, enter the value through the command line.
# Run sh multi_scp.sh conf_file_path file target
If [-z "$3"]
Then
Echo "Sh multi_scp.sh conf_file_path file target ";
Exit;
Fi
Default_ssh_user = "root"
Default_ssh_port = "22 ";
# Upload shell script file path
Scp_upload = scp_upload.sh
# Configure file path
Conf_file = $1
# Then upload file path
Scp_file = $2
# Remote hosttarget file or dir path
Scp_target = $3
# Determine whether the conf_file configuration file exists
If [! -E "$ conf_file"]
Then
Echo "$ conf_file is not exists ";
Exit;
Fi
# Determine whether scp_file is a file or directory
If [! -E "$ scp_file"] & [! -D "$ scp_file"]
Then
Echo "$ scp_file is not exists ";
Exit;
Fi
# Read configure file
Source $ conf_file
# If the password is not provided in the configuration file, enter
If ["$ {# ssh_passwords [@]}" = "0"] | ["$ {# ssh_passwords [@]}"-lt "$ {# ssh_hosts [@]} "]
Then
Read-P "Please input password:"-S default_ssh_password
Fi
Success_hosts = "";
Fail_hosts = "";
For (I = 0; I <$ {# ssh_hosts [@]}; I ++ ))
Do
# Remote SSH host
Ssh_host =$ {ssh_hosts [$ I]};
# Remote SSH port
Ssh_port =$ {ssh_ports [$ I]};
If ["$ ssh_port" = ""]
Then
Ssh_port = $ default_ssh_port;
Fi
# Remote SSH user
Ssh_user =$ {ssh_users [$ I]};
If ["$ ssh_user" = ""]
Then
Ssh_user = $ default_ssh_user;
Fi
# Remote SSH Password
Ssh_password =$ {ssh_passwords [$ I]};
If ["$ ssh_password" = ""]
Then
Ssh_password = $ default_ssh_password;
Fi
Echo "[" 'date + "% F % t" '"] (SCP-r $ scp_file $ ssh_user @ $ ssh_host: $ ssh_port: $ scp_target) start"
# SCP file or dir
/Usr/bin/empty CT scp_upload.sh "$ ssh_host" "$ ssh_port" "$ ssh_user" "$ ssh_password" "$ scp_file" "$ scp_target"
If ["$? "-EQ" 0 "]
Then
Success_hosts = "$ success_hosts, $ ssh_host"
Else
Fail_hosts = "$ fail_hosts, $ ssh_host"
Fi
Echo "[" 'date + "% F % t" '"] (SCP-r $ scp_file $ ssh_user @ $ ssh_host: $ ssh_port: $ scp_target) end"
Echo ""
Done
Echo "success_hosts = [$ success_hosts]"
Echo "fail_hosts = [$ fail_hosts]"
2. Source Code of scp_upload.sh
#! /Usr/bin/CT
# Author: yifangyou
# Create time: 2011-05-17
# Host
Set scphost "[lindex $ argv 0]"
# Ssh port
Set port "[lindex $ argv 1]"
# SSH user name
Set scpuser "[lindex $ argv 2]"
# SSH Password
Set scppw "[lindex $ argv 3]"
# File name or directory to be uploaded
Set file "[lindex $ argv 4]"
# Name or directory of the file to be uploaded to the remote machine
Set target "[lindex $ argv 5]"
Spawn SCP-r-p $ port $ File $ scpuser @ $ scphost: $ Target
# Set the timeout time to prevent remote machine firewall from being suspended.
Set timeout 30
CT {
# Respose: "root@1.2.3.4s password:", automatically enter the password
"* Password *"{
Set timeout 30
Send "$ scppw"
}
# The first connect will respose "are you sure you want to continue connecting (Yes/No )? Yes"
"* Yes *"{
Set timeout 30
Send "yes"
Set timeout 30
Login CT "* password *"
Set timeout 30
Send "$ scppw"
}
Busy {send_user "<error: Busy>"; Exit 1 ;}
Failed {send_user "<error: Failed>"; Exit 2 ;}
Timeout {send_user "<error: timeout>"; Exit 3 ;}
}
# Permission denied not try again, Return Error Information
Set timeout 30
CT {
"* Denied *"{
Send_user "<error: Permission denied>"
Exit 4
}
"* No such file *"{
Send_user "<error: no such File>"
Exit 5
}
Busy {send_user "<error: Busy>"; exit 6 ;}
Failed {send_user "<error: Failed>"; exit 7 ;}
Timeout {send_user "<error: timeout>"; exit 8 ;}
}
Exit 0
3. Configuration File Format: SCP. conf
# Ssh_hosts = ("1.1.1.1" "2.2.2.2 ")
# Ssh_ports = ("22" "22") # Wheen port_num # Ssh_users = ("root" "root") # Wheen user_num # Ssh_passwords = ("323" "222") # Wheen password_num 4. Run the code
Find a machine that can be connected to the machine to be uploaded and install the secondary CT (you can use the secondary CT command to test whether it has been installed)
Put scp_upload.sh, multi_scp_upload.sh, and SCP. conf in the same directory and run multi_scp_upload.sh.