Get the App
SLTechnology News&Howtos  ›  Servers  › 

30 classic cases of Shell scripts (part two)

Shulou Source: shulou.com Published: 2022-06-02 18:18:21 10月04日 Update

This article catalogue

21. Download the file 22 from the FTP server and enter 5 numbers less than 100 in a row Statistical sum, minimum and maximum 23, assign the result to variable 24, batch modify file name 25, count the total size of files ending in .html in the current directory 26, scan host port status 27, Expect implements SSH interactive execution command 28, batch modify server user password 29, print multiplication formula 30, getopts tool improves script command line parameters

21. Download files from the FTP server

#! / bin/bashif [$#-ne 1]; then echo "Usage: $0 filename" fidir=$ (dirname $1) file=$ (basename $1) ftp-n-v / dev/null > / dev/tcp/$HOST/$PORT; then echo "$PORT open" else echo "$PORT close" fidone

27. Expect implements SSH without interactive execution commands

Expect is a tool for automated interactive applications, such as telnet,ftp,passwd. You need to install the expect package first. Method 1:EOF standard output as expect standard input #! / bin/bashUSER=rootPASS=123.comIP=192.168.1.120expect > $NEW_INFO expect-c "spawn ssh-p$PORT $USER@$IP set timeout 2 expect {\" (yes/no)\ "{send\" yes\ r\ "; exp_continue}\" password:\ "{send\" $PASS\ r\ " Exp_continue}\ "$USER@*\" {send\ "echo\'$NEW_PASS\'| passwd-- stdin $USER\ r exit\ r\"; exp_continue}} "done generates a new password file: # cat new_pass.txt 192.168.18.217 root n8wX3mU% 22192.168.18.218 root c87entZnnL 22

29. Print the multiplication formula

Method 1 for # awk 'BEGIN {for

Tags: Methods scripts parameters files commands servers services inputs variables passwords hosts tools statistics locations letters formats directories results maximum minimum Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi NVidia macOS Linux