bash

Validate the number of arguments passed in bash from read

泪湿孤枕 提交于 2021-02-05 06:06:15
问题 I have a question about validating user input regarding number of arguments passed by the user in a bash script. For example, if I use: if [[ $# -eq 2 ]] then... that will check if 2 arguments passed from the command line like this: ./somescript.sh arg1 arg2 but how to validate if user passed 2 arguments when asked? For example: echo "Type 2 names:" read... if [[ user passed more || less than 2 arguments]] echo "incorrect number of names" Now if I try to use $# -eq 2 it doesn't work. What's

Save ssh -V to variable

余生长醉 提交于 2021-02-05 06:00:20
问题 I am trying to automate the testing of passwordless ssh from 72 remote servers back to a central server. I have central server passwordless ssh working to the 72 servers, but need it working from them back the the central server. The 72 servers have one of two ssh versions. OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 OR sshg3: SSH Tectia Client 6.1.8 on x86_64-unknown-linux-gnu Build: 136 Product: SSH Tectia Client License type: commercial The issue I am experience is trying to save

Multiple read from a txt file in bash (parallel processing )

一世执手 提交于 2021-02-05 05:57:53
问题 Here is a simple bash script for HTTP status code while read url do urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "${url}" --max-time 5 ) echo "$url $urlstatus" >> urlstatus.txt done < $1 I am reading URL from text file but it processes only one at a time, taking too much time, GNU parallel and xargs also process one line at time (tested) How to process simultaneous URL for processing to improve timing? In other words threading of URL file rather than bash commands

Bash Select Menu Formatting without Tabs

♀尐吖头ヾ 提交于 2021-02-05 04:58:06
问题 I've built a simple select menu in Bash. It's currently displaying the menu horizontally (with tabs) like so: 1) Create a VM from scratch 3) Command-line Usage 2) Management Menu 4) Quit I'd like the list to look like this: 1) Create a VM from scratch 2) Management Menu 3) Command-line Usage 4) Quit UPDATE : Here's my code: PS3="Please choose a valid option : " OPTIONS=("Create a VM from scratch" "Management Menu" "Command-line Usage" "Quit") select opt in "${OPTIONS[@]}"; do case $opt in

Bash Select Menu Formatting without Tabs

血红的双手。 提交于 2021-02-05 04:57:15
问题 I've built a simple select menu in Bash. It's currently displaying the menu horizontally (with tabs) like so: 1) Create a VM from scratch 3) Command-line Usage 2) Management Menu 4) Quit I'd like the list to look like this: 1) Create a VM from scratch 2) Management Menu 3) Command-line Usage 4) Quit UPDATE : Here's my code: PS3="Please choose a valid option : " OPTIONS=("Create a VM from scratch" "Management Menu" "Command-line Usage" "Quit") select opt in "${OPTIONS[@]}"; do case $opt in

Bash Select Menu Formatting without Tabs

时光总嘲笑我的痴心妄想 提交于 2021-02-05 04:57:14
问题 I've built a simple select menu in Bash. It's currently displaying the menu horizontally (with tabs) like so: 1) Create a VM from scratch 3) Command-line Usage 2) Management Menu 4) Quit I'd like the list to look like this: 1) Create a VM from scratch 2) Management Menu 3) Command-line Usage 4) Quit UPDATE : Here's my code: PS3="Please choose a valid option : " OPTIONS=("Create a VM from scratch" "Management Menu" "Command-line Usage" "Quit") select opt in "${OPTIONS[@]}"; do case $opt in

How to remove duplicate words from a string in a Bash script?

二次信任 提交于 2021-02-05 04:55:03
问题 I have a string containing duplicate words, for example: abc, def, abc, def How can I remove the duplicates? The string that I need is: abc, def 回答1: We have this test file: $ cat file abc, def, abc, def To remove duplicate words: $ sed -r ':a; s/\b([[:alnum:]]+)\b(.*)\b\1\b/\1\2/g; ta; s/(, )+/, /g; s/, *$//' file abc, def How it works :a This defines a label a . s/\b([[:alnum:]]+)\b(.*)\b\1\b/\1\2/g This looks for a duplicated word consisting of alphanumeric characters and removes the

How to remove duplicate words from a string in a Bash script?

断了今生、忘了曾经 提交于 2021-02-05 04:53:39
问题 I have a string containing duplicate words, for example: abc, def, abc, def How can I remove the duplicates? The string that I need is: abc, def 回答1: We have this test file: $ cat file abc, def, abc, def To remove duplicate words: $ sed -r ':a; s/\b([[:alnum:]]+)\b(.*)\b\1\b/\1\2/g; ta; s/(, )+/, /g; s/, *$//' file abc, def How it works :a This defines a label a . s/\b([[:alnum:]]+)\b(.*)\b\1\b/\1\2/g This looks for a duplicated word consisting of alphanumeric characters and removes the

How to remove duplicate words from a string in a Bash script?

可紊 提交于 2021-02-05 04:52:38
问题 I have a string containing duplicate words, for example: abc, def, abc, def How can I remove the duplicates? The string that I need is: abc, def 回答1: We have this test file: $ cat file abc, def, abc, def To remove duplicate words: $ sed -r ':a; s/\b([[:alnum:]]+)\b(.*)\b\1\b/\1\2/g; ta; s/(, )+/, /g; s/, *$//' file abc, def How it works :a This defines a label a . s/\b([[:alnum:]]+)\b(.*)\b\1\b/\1\2/g This looks for a duplicated word consisting of alphanumeric characters and removes the

[Rman]Oracle Rman增量备份Level012脚本

假如想象 提交于 2021-02-05 03:05:41
Rman Level012备份实验 http://blog.csdn.net/u011364306/article/details/50036429 采用0221222增量备份策略,7天一个轮回 也就是周日0级备份,周1 2 4 5 6 采用2级增量备份,周3采用1级增量备份 打开控制文件自动备份 [sql]view plaincopy CONFIGURE CONTROLFILE AUTOBACKUP ON; 11g控制文件自动备份新特性: http://blog.csdn.net/u011364306/article/details/50051303 配置控制文件备份路径 [sql]view plaincopy RMAN > CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO'/file/backup/rman/controlfile_%F'; 将过期天数设为7天 [sql]view plaincopy RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS; 数据备份目录 [sql]view plaincopy $ mkdir -p /file/backup/rman/ 脚本解释: [sql]view plaincopy vim