[英]Increment a variable by 1 bash
您好,我是bash和linux的超级新手,但是我试图修改脚本,我必须能够创建一个文件,并在该文件中打印我所请求的内容,但每次将端口号增加一。
这就是我现在所拥有的,但不能完成任务。
rm -rf /etc/squid_squid_user
touch /etc/squid_squid_user
IPADDRESS=$(wget ipinfo.io/ip -q -O -)
portid=10000
portid=(($portid+1))
clear
echo "Enter a username for your proxies."
read username
echo
echo "Enter a password for your proxies."
read password
htpasswd -cdb /etc/squid/squid_user $username $password
sudo tee -a proxies.txt <<EOF
$IPADDRESS:$portid:$username:$password
EOF
我将希望输出像下面的示例
45.32.14.256:10001:test:run
45.32.14.256:10002:test:run
45.32.14.256:10003:test:run
45.32.14.256:10004:test:run
45.32.14.256:10005:test:run
我已经注释了原始代码的几行,并引入了一个循环。
# Original code: IPADDRESS=$(wget ipinfo.io/ip -q -O -)
IPADDRESS=45.32.14.256
# Original code: variable number set earlier
read -p "How many proxies? " number
portid=1000
((maxport=portid+number))
while (( portid < maxport)); do
((portid++))
# original code: clear
echo "Enter a username for your proxies."
# original code: read username
username=test
echo
echo "Enter a password for your proxies."
# original code: read password
password=run
# Original code: htpasswd -cdb /etc/squid/squid_user $username $password
sudo tee -a /tmp/proxies.txt <<EOF
$IPADDRESS:$portid:$username:$password
EOF
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.