# value equal if [ ${ans_lines} -eq ${lines} ] then echo "lines is ok" else echo "lines is not ok" fi # file exist hdfs dfs -test -d ${HDFS_path}/wap if [ $? == 0 ]; then hdfs dfs -rmr ${HDFS_path}/wap fi
for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
for i in {1..10}; do echo $i; done echo "**************" END=10 for i in $(seq 1 $END); do echo $i; done echo "**************" INTERVAL=2 for i in $(seq 1 $INTERVAL $END); do echo $i; done
for i in {2..5}; do tablesuffix=$i echo $tablesuffix sleep 1; done
# Function to list remote directory sftp_ls() { local nickname=$1 local remote_path=${2:-.} get_config "$nickname" sshpass -p "$password" sftp -P "$port""$user@$host" << EOL cd "$remote_path" ls bye EOL }
# Function to download files/directories sftp_get() { local nickname=$1 local remote_path=$2 local local_path=${3:-.} get_config "$nickname" if [[ "$remote_path" == */ ]]; then # It's a directory sshpass -p "$password" sftp -P "$port""$user@$host" << EOL get -r "$remote_path" "$local_path" bye EOL else # It's a file sshpass -p "$password" sftp -P "$port""$user@$host" << EOL get "$remote_path" "$local_path" bye EOL fi }
# Function to upload files/directories sftp_put() { local nickname=$1 local local_path=$2 local remote_path=${3:-.} get_config "$nickname" if [ -d "$local_path" ]; then # It's a directory sshpass -p "$password" sftp -P "$port""$user@$host" << EOL put -r "$local_path" "$remote_path" bye EOL else # It's a file sshpass -p "$password" sftp -P "$port""$user@$host" << EOL put "$local_path" "$remote_path" bye EOL fi }
# Main menu case"$1"in "add") add_config ;; "ls") if [ -z "$2" ]; then echo"Usage: $0 ls <nickname> [remote_path]" exit 1 fi sftp_ls "$2""$3" ;; "get") if [ -z "$3" ]; then echo"Usage: $0 get <nickname> <remote_path> [local_path]" exit 1 fi sftp_get "$2""$3""$4" ;; "put") if [ -z "$3" ]; then echo"Usage: $0 put <nickname> <local_path> [remote_path]" exit 1 fi sftp_put "$2""$3""$4" ;; *) echo"Usage: $0 {add|ls|get|put} [arguments]" echo"Commands:" echo" add Add new SFTP configuration" echo" ls <nickname> [path] List remote directory contents" echo" get <nickname> <remote_path> [local_path] Download file/directory" echo" put <nickname> <local_path> [remote_path] Upload file/directory" exit 1 ;; esac
loop file in dir
1 2 3 4 5 6 7
fileList=`ls *$DT_time*.zip` fileArr=($fileList) for fileName in ${fileArr[@]} do unzip $unzip_name done
tar
打包、排除指定文件、删除源文件
1
tar -zcf wap.tar.gz wap --exclude *.zip --remove-files
tmp = set() lines = output.split('\n') for line in lines: if str(line).startswith('tcp'): items = str(line).split() if not items[3].startswith('127.0.0.1') : if items[3].startswith('0.0.0.0') or items[3].startswith(':::') or items[3].split(':')[0] != items[4].split(':')[0]: print('%s\t\t%s\t\t%s' %(items[3], items[4], items[6])) tmp.add(int(items[3].split(':')[-1]))
listeningPort=list(tmp) listeningPort.sort() listeningPort # listeningPort.sort() for p in listeningPort: print(p) ######### inUsePortInfo = {} retCode,output = commands.getstatusoutput('netstat -ntp -4 |grep ESTABLISHED') lines = output.split('\n') for line in lines: if str(line).startswith('tcp'): items = str(line).split() if items[3].split(':')[0] != items[4].split(':')[0]: port = items[3].split(':')[1] + ' ' + items[6] # print(line) tmp = inUsePortInfo.get(port, list()) tmp.append(items[4]) tmp.sort() inUsePortInfo[port] = tmp # for k,v in inUsePortInfo.items(): # print('%s \t %s' %(k, v))
for i in sorted(inUsePortInfo): print('%s \t %s' %(i, inUsePortInfo[i]))
listeningPort.sort() listeningPort
Expected Output: port, foreign address list
Filter local server 127.0.0.1 local 和 remoter 都是本机
# Define IP addresses array ip_list=( "192.168.1.10" "10.0.0.15" "172.16.0.20" )
# Port to check PORT=1019
# Function to check port connectivity check_port() { local ip=$1 result=$(timeout 3 telnet "$ip"$PORT 2>&1) ifecho"$result" | grep -q "Connected to"; then return 0 else return 1 fi }
echo"Checking port $PORT connectivity..." echo"Unreachable IPs:"
# Check each IP for ip in"${ip_list[@]}"; do if ! check_port "$ip"; then echo"$ip" fi done